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

Python protobuf refuses to work when converting modules into packages #9535

Closed
wouterdb opened this issue Feb 23, 2022 · 1 comment
Closed
Assignees
Labels

Comments

@wouterdb
Copy link

wouterdb commented Feb 23, 2022

What version of protobuf and what language are you using?
Version: 3.19.4 (latest)
Language: Python

What operating system (Linux, Windows, ...) and version?
Linux

What runtime / compiler are you using (e.g., python version or gcc version)
Python 3.6

What did you do?
Steps to reproduce the behavior:

  1. generate a protobuf implementation
  2. move the file {something}_pb2.py to {something}_pb2/__init__.py (which is, as far as python is concerned, the exact same thing)
  3. use the generate client

What did you expect to see

That this works

What did you see instead?

An exception stating

Descriptors should not be created directly, but only retrieved from their parent.

Anything else we should know about your project / environment

This fails because of this check
https://github.com/protocolbuffers/protobuf/blob/HEAD/python/google/protobuf/pyext/descriptor.cc#L130
That doesn't include the ability of every module in python to be in a file __init__.py.

For me, it would be best if this check was removed completely.
It think using stack inspection is, in general, a risky proposition and very unpythonic (and thus, not well supported in python).
I understand that these methods are not part of the external API of the library, and it is good to warn programmers of their mistakes, but it also violates the programming principle that a method should not respond differently based on who calls it.

Wouter

@elharo elharo changed the title Python protobug refuses to work when converting modules into packages Python protobuf refuses to work when converting modules into packages Feb 23, 2022
@elharo elharo added the python label Feb 23, 2022
@anandolee
Copy link
Contributor

From 3.20.0, we have simplified the python generated code which the check should not invoked. Both protoc and python runtime need to be 3.20.0 or above

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

3 participants