ydb-python-sdk icon indicating copy to clipboard operation
ydb-python-sdk copied to clipboard

bug: exception on `import ydb`, installing older protobuf fixes

Open blinkov opened this issue 8 months ago • 1 comments

Bug Report

YDB Python SDK version:

3.21.1

Environment

Docker container with:

# uname -a
Linux f9516947cb92 6.8.0-47-generic #47-Ubuntu SMP PREEMPT_DYNAMIC Fri Sep 27 22:03:50 UTC 2024 aarch64 Linux

Exception on import ydb, installing older protobuf fixes:

...
Installing collected packages: protobuf, propcache, packaging, multidict, idna, grpcio, frozenlist, attrs, aiohappyeyeballs, yarl, aiosignal, aiohttp, ydb
Successfully installed aiohappyeyeballs-2.6.1 aiohttp-3.11.18 aiosignal-1.3.2 attrs-25.3.0 frozenlist-1.6.0 grpcio-1.71.0 idna-3.10 multidict-6.4.3 packaging-25.0 propcache-0.3.1 protobuf-5.29.4 yarl-1.20.0 ydb-3.21.1

[notice] A new release of pip is available: 25.0.1 -> 25.1.1
[notice] To update, run: pip install --upgrade pip
((venv) ) /app # python3
Python 3.12.10 (main, Apr 10 2025, 15:27:01) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ydb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/app/venv/lib/python3.12/site-packages/ydb/__init__.py", line 9, in <module>
    from .credentials import *  # noqa
    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.12/site-packages/ydb/credentials.py", line 5, in <module>
    from . import tracing, issues, connection
  File "/app/venv/lib/python3.12/site-packages/ydb/issues.py", line 9, in <module>
    from . import _apis
  File "/app/venv/lib/python3.12/site-packages/ydb/_apis.py", line 28, in <module>
    from ._grpc.common import (
  File "/app/venv/lib/python3.12/site-packages/ydb/_grpc/v5/ydb_cms_v1_pb2_grpc.py", line 5, in <module>
    from ydb._grpc.v5.protos import ydb_cms_pb2 as protos_dot_ydb__cms__pb2
  File "/app/venv/lib/python3.12/site-packages/ydb/_grpc/v5/protos/ydb_cms_pb2.py", line 15, in <module>
    from ydb._grpc.v5.protos import ydb_operation_pb2 as protos_dot_ydb__operation__pb2
  File "/app/venv/lib/python3.12/site-packages/ydb/_grpc/v5/protos/ydb_operation_pb2.py", line 17, in <module>
    from ydb._grpc.v5.protos.annotations import validation_pb2 as protos_dot_annotations_dot_validation__pb2
  File "/app/venv/lib/python3.12/site-packages/ydb/_grpc/v5/protos/annotations/validation_pb2.py", line 23, in <module>
    google_dot_protobuf_dot_descriptor__pb2.FieldOptions.RegisterExtension(required)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: type object 'FieldOptions' has no attribute 'RegisterExtension'
>>>
((venv) ) /app # pip3 install 'protobuf<5'
Collecting protobuf<5
  Downloading protobuf-4.25.7-py3-none-any.whl.metadata (541 bytes)
Downloading protobuf-4.25.7-py3-none-any.whl (156 kB)
Installing collected packages: protobuf
  Attempting uninstall: protobuf
    Found existing installation: protobuf 5.29.4
    Uninstalling protobuf-5.29.4:
      Successfully uninstalled protobuf-5.29.4
Successfully installed protobuf-4.25.7

[notice] A new release of pip is available: 25.0.1 -> 25.1.1
[notice] To update, run: pip install --upgrade pip
((venv) ) /app # python3
Python 3.12.10 (main, Apr 10 2025, 15:27:01) [GCC 14.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ydb
>>>

blinkov avatar May 16 '25 02:05 blinkov

The problem is that protobuf files for python protobuf library with versions newer than 5.26 actually can't be imported with python parser.

On user side this can be circumvented by using upb parser via setting environment variable PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=upb

tsbalzhanov avatar Oct 09 '25 11:10 tsbalzhanov