TypeError produced by python implementation when upb works fine
What version of protobuf and what language are you using? Version: v6.31.1 Language: Python
What operating system (Linux, Windows, ...) and version? Fedora Linux 42 amd64
What runtime / compiler are you using (e.g., python version or gcc version)
$ python3 --version
Python 3.13.3
What did you do? Steps to reproduce the behavior:
$ pip3 install onnx
$ PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python python3
import onnx
key = 'value'
attr_type = onnx.onnx_cpp2py_export.defs.OpSchema.AttrType.TENSOR
data = onnx.AttributeProto(name=key, type=attr_type)
What did you expect to see No error.
What did you see instead?
Traceback (most recent call last):
File "/home/user/.local/lib/python3.13/site-packages/google/protobuf/internal/python_message.py", line 728, in field_setter
new_value = type_checker.CheckValue(new_value)
File "/home/user/.local/lib/python3.13/site-packages/google/protobuf/internal/type_checkers.py", line 164, in CheckValue
raise TypeError(message)
TypeError: <AttrType.TENSOR: 4> has type <class 'onnx.onnx_cpp2py_export.defs.OpSchema.AttrType'>, but expected one of: (<class 'int'>,)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/user/.local/lib/python3.13/site-packages/google/protobuf/internal/python_message.py", line 587, in init
setattr(self, field_name, field_value)
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/.local/lib/python3.13/site-packages/google/protobuf/internal/python_message.py", line 730, in field_setter
raise TypeError(
'Cannot set %s to %.1024r: %s' % (field.full_name, new_value, e))
TypeError: Cannot set onnx.AttributeProto.type to <AttrType.TENSOR: 4>: <AttrType.TENSOR: 4> has type <class 'onnx.onnx_cpp2py_export.defs.OpSchema.AttrType'>, but expected one of: (<class 'int'>,)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<python-input-2>", line 4, in <module>
data = onnx.AttributeProto(name=key, type=attr_type)
File "/home/user/.local/lib/python3.13/site-packages/google/protobuf/internal/python_message.py", line 589, in init
_ReraiseTypeErrorWithFieldName(message_descriptor.name, field_name)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/.local/lib/python3.13/site-packages/google/protobuf/internal/python_message.py", line 478, in _ReraiseTypeErrorWithFieldName
raise exc.with_traceback(sys.exc_info()[2])
File "/home/user/.local/lib/python3.13/site-packages/google/protobuf/internal/python_message.py", line 587, in init
setattr(self, field_name, field_value)
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/user/.local/lib/python3.13/site-packages/google/protobuf/internal/python_message.py", line 730, in field_setter
raise TypeError(
'Cannot set %s to %.1024r: %s' % (field.full_name, new_value, e))
TypeError: Cannot set onnx.AttributeProto.type to <AttrType.TENSOR: 4>: <AttrType.TENSOR: 4> has type <class 'onnx.onnx_cpp2py_export.defs.OpSchema.AttrType'>, but expected one of: (<class 'int'>,) for fie
ld AttributeProto.type
Anything else we should know about your project / environment
No such errors happen when default backend upb is used.
But there are no prebuilt protobuf packages on pypi for s390x with upb backend, only fallback none-any version with python backend only:
https://pypi.org/project/protobuf/6.31.1/#files
Due to that code like this does not work on s390x.
cc @anandolee
hi
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.
This issue is labeled inactive because the last activity was over 90 days ago. This issue will be closed and archived after 14 additional days without activity.
This issue still reproduces with protobuf 6.32.1.
We will look into supporting s390x as we are moving towards Python upb as the default.
This issue reproduces on amd64 (aka x86 or x86_64) when python backend is used.
I have a PR out for building s390x binary wheels: https://github.com/protocolbuffers/protobuf/pull/23527