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

[Python] Error when creating python protobuf object: MergeFrom() must be instance of same class #17647

Open
maxnoe opened this issue Jul 29, 2024 · 2 comments
Assignees
Labels

Comments

@maxnoe
Copy link

maxnoe commented Jul 29, 2024

What version of protobuf and what language are you using?

protobuf / libprotobuf 4.25.3 from conda-forge

What operating system (Linux, Windows, ...) and version?

Linux (Ubuntu 22.04)

What runtime / compiler are you using (e.g., python version or gcc version)

python, tested with multiple versions, 3.9, 3.10, 3.11

What did you do?

Minimal example:

from protozfits.CoreMessages_pb2 import AnyArray
from protozfits.R1v1_debug_pb2 import DebugCameraConfiguration

debug = DebugCameraConfiguration(
    tdp_type=AnyArray(type=AnyArray.U16, data=8 * b'\x00')
)

this fails using the latest protozfits from conda, which depends on protobuf 4.25.3, to reproduce:

$ mamba create -n proto-test python=3.11 protozfits=2.5.1
$ mamba activate proto-test
$ mamba list proto
# packages in environment at /home/mnoethe/.local/conda/envs/proto-test:
#
# Name                    Version                   Build  Channel
libprotobuf               4.25.3               h08a7969_0    conda-forge
protobuf                  4.25.3          py311h7b78aeb_0    conda-forge
protozfits                2.5.1           py311hcf1f2b2_0    conda-forge
$ python test_proto.py # contains the snippet posted above
Traceback (most recent call last):
  File "/home/mnoethe/Uni/CTA/test_protozfits.py", line 5, in <module>
    debug = DebugCameraConfiguration(
            ^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Parameter to MergeFrom() must be instance of same class: expected AnyArray got AnyArray.

What did you expect to see
No error, code works.

What did you see instead?
The error posted above.

Anything else we should know about your project / environment

This error happens with the conda package built using conda-forge.

The python bindings code is generated using the protoc cmake integration as the project also interacts with C++ code.

This seems similar to #10040, which was closed with unclear resolution.

@maxnoe maxnoe added the untriaged auto added to all issues by default when created. label Jul 29, 2024
@maxnoe
Copy link
Author

maxnoe commented Jul 30, 2024

For some reason I don't understand, the types are not identical in the conda package, but they are in the pip package:

from protozfits.CoreMessages_pb2 import AnyArray
from protozfits.R1v1_pb2 import Event

event = Event()

print(event.waveform.__class__, id(event.waveform.__class__))
print(AnyArray, id(AnyArray))
print(id(AnyArray) == id(event.waveform.__class__))

Output in the conda env:

<class 'AnyArray'> 94075357242176
<class 'CoreMessages_pb2.AnyArray'> 94075364251936
False

Output using the PyPI package:

<class 'CoreMessages_pb2.AnyArray'> 94617635118128
<class 'CoreMessages_pb2.AnyArray'> 94617635118128
True

@shaod2
Copy link
Member

shaod2 commented Aug 6, 2024

I think there might be multiple messages out there with the same names but different path. Probably check if there're duplicates and import the correct one

@shaod2 shaod2 added python and removed untriaged auto added to all issues by default when created. labels Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants