For my GAE app, I was updating the libs in my requirements.txt, and after doing so, I get error messages relating to protobuf.
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:
- Downgrade the protobuf package to 3.20.x or lower.
- 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
I'm not using protobuf directly so it seems that other Google libraries are using it. Adding
protobuf==3.20.3
to my requirements.text fixes it.
But... what is going on and for how long do I need to do this? I haven't found any helpful info online from Google.
It is troubling to have to pin a library to an old version because at some point something will break.
CodePudding user response:
As of the moment, protocol buffer version 4.21.0
contains some breaking changes when using it. Since you mentioned that you use protobuf indirectly, Python is still calling the latest update. You can check this link on Protocol Buffers for Python Updates.
As a workaround, as suggested by the error message, you can either install protobuf version 3.20.x
or lower or set protobuf==3.20.x
in your requirements.txt
file to override the latest version.
We don't have the timeframe on how long do we need to perform this workaround until Google provides us with a fix.
I also suggest to file a bug as this is definitely a major issue that needs to be addressed.
Update:
A bug was previously filed for version 4.21.0
in github and it was suggested that version 3.19.x
or 3.20.x
should be used for now and a feature request to add a backward compatibility layer was already been raised.
CodePudding user response:
What is going on?
Protobuf planned a breaking change, and released it, updating the major revision number.
When this happened, users of protobuf should have regenerated with the latest version. But Google did not regenerate their libraries with the latest version.
How long do I need to pin protobuf to an old version?
Until Google fixes their code. File a bug report with the Google libraries that are using protobuf and causing this error for you.
It is troubling to have to pin a library to an old version because at some point something will break.
Using out of date libraries is a security concern, because they will not have the latest security patches.
Other than that, though, there is nothing inherently less stable about using a pinned version than always using the latest version. In fact, (with a few exceptions,) usually the opposite is true; it is more stable. Pinning a dependency results in deterministic repeatable deployment and makes sure that every developer is testing on the very same codebase.