Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couldn't build proto file into descriptor pool [Python 3.13] #490

Closed
cdce8p opened this issue Sep 28, 2024 · 2 comments · Fixed by #492
Closed

Couldn't build proto file into descriptor pool [Python 3.13] #490

cdce8p opened this issue Sep 28, 2024 · 2 comments · Fixed by #492
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. status: investigating The issue is under investigation, which is determined to be non-trivial. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@cdce8p
Copy link

cdce8p commented Sep 28, 2024

Encountered this issue while testing Python 3.13.0rc2. To reproduce

import proto

__protobuf__ = proto.module(
    package="some_module",
    manifest={"View", "Encoding"},
)

class View(proto.Enum):
    A = 0

class Encoding(proto.Enum):
    B = 0
$ python test.py
Traceback (most recent call last):
  File "/.../proto-plus-python/test.py", line 11, in <module>
    class Encoding(proto.Enum):
        B = 0
  File "/.../proto-plus-python/proto/enums.py", line 105, in __new__
    file_info.generate_file_pb(new_class=cls, fallback_salt=full_name)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/.../proto-plus-python/proto/_file_info.py", line 104, in generate_file_pb
    pool.Add(self.descriptor)
    ~~~~~~~~^^^^^^^^^^^^^^^^^
TypeError: Couldn't build proto file into descriptor pool: duplicate symbol 'some_module.__firstlineno__'
$ pip list
Package    Version
---------- -------
pip        24.2
proto-plus 1.24.0
protobuf   5.28.2

--
AFAICT the issue shows up as soon as two proto.Enum are defined in one module. A quick experiment suggests that the reason might be here

value=sorted(
(
descriptor_pb2.EnumValueDescriptorProto(name=name, number=number)
# Minor hack to get all the enum variants out.
for name, number in attrs.items()
if isinstance(number, int)
),

The attributes are only filtered by if isinstance(number, int). Python 3.13 added the new __firstlineno__ attribute which is an integer and as such not filtered as it should be. Just changing the condition here would be enough to resolve it, just not sure that's the best option as I'm unfamiliar with the code base.

-if isinstance(number, int)
+if isinstance(number, int) and name != "__firstlineno__"
@cdce8p cdce8p added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Sep 28, 2024
@cdce8p
Copy link
Author

cdce8p commented Oct 5, 2024

@parthea Would you mind taking a look at this? It would be awesome to have support for Python 3.13 before the release next week. Especially since protobuf and grpcio are already compatible.

@cdce8p
Copy link
Author

cdce8p commented Oct 9, 2024

Some of the affected packages. There might be more

  • google-cloud-texttospeech==2.17.2
import google.cloud.texttospeech
  • google-cloud-speech==2.27.0
import google.cloud.speech_v1
  • google-generativeai==0.8.3
import google.generativeai
  • google-cloud-pubsub==2.26.0
import google.cloud.pubsub_v1

@parthea parthea self-assigned this Oct 10, 2024
@parthea parthea added the status: investigating The issue is under investigation, which is determined to be non-trivial. label Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. status: investigating The issue is under investigation, which is determined to be non-trivial. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants