MobilityData/gtfs-realtime-bindings

Python: Deprecation warnings for _descriptor

Opened this issue · 4 comments

Version: 0.0.6
Python version: 3.9
OS: Fedora 33

Issue:
GTFS realtime bindings for Python are reporting a deprecation warning for EnumDescriptor(), EnumValueDescriptor(), FileDescriptor(), FieldDescriptor(), Descriptor()

Example:

WARNING - .../local/lib/python3.9/site-packages/google/transit/gtfs_realtime_pb2.py:381: DeprecationWarning: Call to deprecated create function FieldDescriptor(). Note: Create unlinked descriptors is going to go away. Please use get/find descriptors from generated code or query the descriptor_pool.
  _descriptor.FieldDescriptor(

Thanks @jsa34ito. I hope to update the Python bindings soon and hopefully this will fix this issue. I'll leave it open so you can provide feedback on the next release.

It looks like this deprecation warning was just upgraded to a hard error, and the Python bindings here don't work anymore on fresh builds. The protobuf PyPI package was updated a few hours ago. The build error I get is:

 gtfsrealtimegenerator.py:1: in <module>
     from google.transit import gtfs_realtime_pb2
 /usr/local/lib/python3.9/site-packages/google/transit/gtfs_realtime_pb2.py:50: in <module>
     _descriptor.EnumValueDescriptor(
 /usr/local/lib/python3.9/site-packages/google/protobuf/descriptor.py:755: in __new__
     _message.Message._CheckCalledFromGeneratedFile()
 E   TypeError: Descriptors cannot not be created directly.
 E   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.
 E   If you cannot immediately regenerate your protos, some other possible workarounds are:
 E    1. Downgrade the protobuf package to 3.20.x or lower.
 E    2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
 E   
 E   More information: https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates

The version of the Python proto library in setup.py is not pinned, so fresh builds are picking up this new release.

I tried to upgrade the bindings using the most recent version of the proto compiler and the Python library, but was unable to get the tests to pass due to this error:

ModuleNotFoundError: No module named 'google.protobuf'

I'm very confused because I just ran pip install protobuf...

As a quick alternative, I created a PR that just pins the Python protobuf library at a 3.X.X version.

Update: the 4.21.0 protobuf was yanked from PyPI because many projects has similar issues to the one here. This is the protobuf GitHub issue. One of the last comments say there will be a roll forward, so the issue here will return soon.

I think the safest option would be to:

  1. Merge in the PR I sent last night and create a new release. This would mean that when the update to the protobuf library happens, gtfs-realtime-bindings will not be affected (as long as consumers upgrate their gtfs-realtime-bindings version).

  2. When the protobuf update happens, create a new PR to actually update the bindings.