You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using options results in descriptor pool error in generated code at import time. #150
Using options results in descriptor pool error in generated code at import time.
Reproduction Steps
I'm trying out betterproto2, and running to an exception in the generated code when trying to add options to some of my files. Here's a minimal example:
uv run python -m grpc_tools.protoc --python_betterproto2_out generated/ --python_betterproto2_opt=google_protobuf_descriptors -I. example.proto
and then try to import the generated code with
uv run python -c "from generated.betterproto.repro import MyMessage"
Expected Results
An exception is raised
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/[snip]/generated/betterproto/repro/__init__.py", line 52, in <module>
EXAMPLE_PROTO_DESCRIPTOR = default_google_proto_descriptor_pool.AddSerializedFile(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Couldn't build proto file into descriptor pool: Depends on file 'google/protobuf/descriptor.proto', but it has not been loaded
Actual Results
The generated code should import without errors.
Potential fix/workaround: If I add
from ...googleimportprotobufas___google__protobuf__
in the generated file (near the top), that resolves the error.
System Information
I'm using uv instead of pip. I'm fairly certain that's not the issue.
Generated modules now import each foreign dependency package (including google.protobuf for custom options) and register same-package files in dependency order before AddSerializedFile. That matches the import workaround in the issue report.
Activity
drewfustin commentedon Sep 9, 2026
Proposed fix in #255.
Generated modules now import each foreign dependency package (including
google.protobuffor custom options) and register same-package files in dependency order beforeAddSerializedFile. That matches the import workaround in the issue report.