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

dfu_cc_pb2.py incompatible with recent protobuf version #548

Open
an0nfunc opened this issue Jun 24, 2024 · 2 comments
Open

dfu_cc_pb2.py incompatible with recent protobuf version #548

an0nfunc opened this issue Jun 24, 2024 · 2 comments

Comments

@an0nfunc
Copy link

Hi 👋

since a recent version of protobuf, protobuf and the generated dfu_cc_pb2.py (in trussed/bootloader/nrf52_upload/dfu) seem to be incompatible:

Traceback (most recent call last):
  File "/usr/bin/nitropy", line 5, in <module>
    from pynitrokey.cli import main
  File "/usr/lib/python3.12/site-packages/pynitrokey/cli/__init__.py", line 26, in <module>
    from pynitrokey.cli.nk3 import nk3
  File "/usr/lib/python3.12/site-packages/pynitrokey/cli/nk3/__init__.py", line 19, in <module>
    from pynitrokey.nk3 import NK3_DATA
  File "/usr/lib/python3.12/site-packages/pynitrokey/nk3/__init__.py", line 14, in <module>
    from pynitrokey.trussed.bootloader.nrf52 import SignatureKey
  File "/usr/lib/python3.12/site-packages/pynitrokey/trussed/bootloader/nrf52.py", line 29, in <module>
    from .nrf52_upload.dfu.init_packet_pb import InitPacketPB
  File "/usr/lib/python3.12/site-packages/pynitrokey/trussed/bootloader/nrf52_upload/dfu/init_packet_pb.py", line 39, in <module>
    from . import dfu_cc_pb2 as pb
  File "/usr/lib/python3.12/site-packages/pynitrokey/trussed/bootloader/nrf52_upload/dfu/dfu_cc_pb2.py", line 34, in <module>
    _descriptor.EnumValueDescriptor(
  File "/usr/lib/python3.12/site-packages/google/protobuf/descriptor.py", line 917, in __new__
    _message.Message._CheckCalledFromGeneratedFile()
TypeError: Descriptors cannot 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

I regenerated the python definition from the protobuf definition found at https://github.com/NordicSemiconductor/pc-nrfutil/blob/master/nordicsemi/dfu/dfu-cc.proto, and it fixes the problem.

I think in the long run this protobuf definition needs to be included in this repo to regenerate the python files as needed.

I'm happy to open a pull request that includes the .proto file and the newly generated dfu_cc_pb2.py. Let me know if you'd like me to proceed with that.

protobuf: 27.1
pynitrokey: 0.4.47

@sosthene-nitrokey
Copy link
Contributor

Hi,

We are also encountering the same issue. A temporary fix you can use is to set the following environment variable:

export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

We will see how we can solve this issue.

@dvzrv
Copy link

dvzrv commented Jul 14, 2024

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