Skip to content

[Python] descriptor_database: items are added with key starting with dot #9867

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

Closed
mcepl opened this issue Apr 27, 2022 · 3 comments
Closed
Assignees
Labels

Comments

@mcepl
Copy link

mcepl commented Apr 27, 2022

What version of protobuf and what language are you using?
Version: 3.20.1
Language: Python

What operating system (Linux, Windows, ...) and version?
Linux/openSUSE/Tumbleweed, all packages from the current distribution

What runtime / compiler are you using (e.g., python version or gcc version)
See details in googleapis/python-api-core#372

What did you do?
Run test suite for python-api-core, while packaging it for openSUSE..

What did you expect to see
Passing test suite.

What did you see instead?
See the above mentioned bug.

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
In the end I have created this patch, which makes the test suite pass, but I guess it is just poorly mitigating bug somewhere else in the code:

---
 python/google/protobuf/descriptor_database.py |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

--- a/python/google/protobuf/descriptor_database.py
+++ b/python/google/protobuf/descriptor_database.py
@@ -75,14 +75,17 @@ class DescriptorDatabase(object):
       for name in _ExtractSymbols(message, package):
         self._AddSymbol(name, file_desc_proto)
     for enum in file_desc_proto.enum_type:
-      self._AddSymbol(('.'.join((package, enum.name))), file_desc_proto)
+      symbol = ('.'.join((package, enum.name))).lstrip('.')
+      self._AddSymbol(symbol, file_desc_proto)
       for enum_value in enum.value:
         self._file_desc_protos_by_symbol[
             '.'.join((package, enum_value.name))] = file_desc_proto
     for extension in file_desc_proto.extension:
-      self._AddSymbol(('.'.join((package, extension.name))), file_desc_proto)
+      symbol = ('.'.join((package, extension.name))).lstrip('.')
+      self._AddSymbol(symbol, file_desc_proto)
     for service in file_desc_proto.service:
-      self._AddSymbol(('.'.join((package, service.name))), file_desc_proto)
+      symbol = ('.'.join((package, service.name))).lstrip('.')
+      self._AddSymbol(symbol, file_desc_proto)

   def FindFileByName(self, name):
     """Finds the file descriptor proto by file name.
@anandolee
Copy link
Contributor

It only happens when package is empty.

The .proto file starts with a package declaration, which helps to prevent naming conflicts between different projects. In Python, packages are normally determined by directory structure, so the package you define in your .proto file will have no effect on the generated code. However, you should still declare package to avoid name collisions in the Protocol Buffers name space as well as in non-Python languages.

@deannagarcia
Copy link
Member

Closing this since the similar issue is fixed: googleapis/python-api-core#372

@mcepl
Copy link
Author

mcepl commented May 5, 2022

Yes, thank you.

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

No branches or pull requests

4 participants