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

Compatibility with protobuf 4.21.0 #159

Open
AntoniaAdler opened this issue Jun 2, 2022 · 5 comments
Open

Compatibility with protobuf 4.21.0 #159

AntoniaAdler opened this issue Jun 2, 2022 · 5 comments

Comments

@AntoniaAdler
Copy link

AntoniaAdler commented Jun 2, 2022

With protobuf update from version 3.20.1 to 4.21.0, the following error is thrown

Traceback (most recent call last):
  ...
    from grpclib.health.service import Health
  File "<repo>/lib/python3.9/site-packages/grpclib/health/service.py", line 10, in <module>
    from .v1.health_pb2 import HealthCheckRequest, HealthCheckResponse
  File "<repo>/lib/python3.9/site-packages/grpclib/health/v1/health_pb2.py", line 34, in <module>
    _descriptor.EnumValueDescriptor(
  File "<repo>/lib/python3.9/site-packages/google/protobuf/descriptor.py", line 755, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

Setting the protobuf version to 3.20.1 fixes the problem.

@vmagamedov
Copy link
Owner

Released grpclib==0.4.3rc3 with updated *_pb2.py files

@upcFrost
Copy link

shouldn't protobuf be listed in the package dependencies? For example, without the protobuf package installed it's impossible to use the Healthcheck as it imports google.protobuf.

@vmagamedov
Copy link
Owner

@upcFrost gRPC states that protobuf is not the only way to serialise requests and replies, so in grpclib it is optional 🤷🏻‍♂️ Health checks are also optional as some other features, grpclib just wants to have some batteries to be included.

BTW, Google's grpcio also doesn't have protobuf as a dependency, only as an optional dependency.

@upcFrost
Copy link

Google's grpcio also doesn't have protobuf as a dependency, only as an optional dependency

Why not make it an optional dependency as well, i.e. grpcio[protobuf]? It will allow the flexibility of specifying which protobuf version are supported. For example, Google's grpcio-tools specifically say that they work with protobuf [required: >=3.12.0,<4.0dev].

Python is currently trying to move towards proper dependency resolution, with pip 22+ and tools like poetry, so imho that'd be a nice change to do, and also a pretty small one. Something like this in setup.cfg should do:

diff --git a/setup.cfg b/setup.cfg
index 3dffb2b..62cd44a 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -29,6 +29,10 @@ python_requires = >=3.7
 install_requires=
     h2<5,>=3.1.0
     multidict
+
+[options.extras_require]
+protobuf =
+    protobuf<4.21.0

 [options.entry_points]
 console_scripts =

@vmagamedov
Copy link
Owner

I think that Google's protobuf and grpcio projects have some problems with versioning. Two times they broke backward compatibility in protobuf.

Right now grpcio-tools requires protobuf<4.0dev,>=3.12.0, so even if grpcio-tools can work with protobuf>4 it will require a new release just to fix this.

Also right now grpcio-health-checking requires protobuf>=3.12.0 and your project will fail to import stubs from this package if you have say protobuf==3.12.2.

So I added protobuf as an optional dependency with only minimum version specified.

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

3 participants