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

Protobuf extensions registerExtension twice cause assertionError #2533

Closed
khenaidoo opened this issue Dec 22, 2016 · 1 comment
Closed

Protobuf extensions registerExtension twice cause assertionError #2533

khenaidoo opened this issue Dec 22, 2016 · 1 comment

Comments

@khenaidoo
Copy link

When using protobuf extensions ("google.protobuf.MessageOptions" and "google.protobuf.FieldOptions") an AssertionError is caused when two modules (in the same process) directly or indirectly import a "_pb2.py" that uses these options. The code in the "_pb2.py" file try to register the extension. Since two modules are importing these extensions then there are two registrations attempt made by the "*_pb2.py" file resulting in an exception in the python/google/protobuf/internal/python_message.py fileas follows:

google_dot_protobuf_dot_descriptor__pb2.MessageOptions.RegisterExtension(yang_child_rule)

File "/usr/local/lib/python2.7/dist-packages/google/protobuf/internal/python_message.py", line 766, in RegisterExtension

cls.DESCRIPTOR.full_name, extension_handle.number))

AssertionError: Extensions "voltha.yang_child_rule" and "voltha.yang_child_rule" both try to extend message type "google.protobuf.MessageOptions" with field number 60000.

Commenting out the assertion error seems to be ok. I locally commented it out as :

def _AddStaticMethods(cls):

TODO(robinson): This probably needs to be thread-safe(?)

def RegisterExtension(extension_handle):
extension_handle.containing_type = cls.DESCRIPTOR
_AttachFieldHelpers(cls, extension_handle)

# Try to insert our extension, failing if an extension with the same number
# already exists.
actual_handle = cls._extensions_by_number.setdefault(
    extension_handle.number, extension_handle)
if actual_handle is not extension_handle:
  return
  # raise AssertionError(
  #     'Extensions "%s" and "%s" both try to extend message type "%s" with '
  #     'field number %d.' %
  #     (extension_handle.full_name, actual_handle.full_name,
  #      cls.DESCRIPTOR.full_name, extension_handle.number))

cls._extensions_by_name[extension_handle.full_name] = extension_handle

This issue seems to have been fixed but there is no release available yet. I am using libprotobuf 3.0.9

@anandolee
Copy link
Contributor

Closing this issue as @khenaidoo said it is fixed and we have new released already.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants