protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

TypeError produced by python implementation when upb works fine

Open AlekseiNikiforovIBM opened this issue 7 months ago • 2 comments

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.

AlekseiNikiforovIBM avatar Jun 05 '25 14:06 AlekseiNikiforovIBM

cc @anandolee

honglooker avatar Jun 05 '25 17:06 honglooker

hi

noelportillo avatar Jun 14 '25 09:06 noelportillo

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.

github-actions[bot] avatar Sep 12 '25 10:09 github-actions[bot]

This issue still reproduces with protobuf 6.32.1.

AlekseiNikiforovIBM avatar Sep 15 '25 08:09 AlekseiNikiforovIBM

We will look into supporting s390x as we are moving towards Python upb as the default.

jguamie avatar Sep 16 '25 17:09 jguamie

This issue reproduces on amd64 (aka x86 or x86_64) when python backend is used.

AlekseiNikiforovIBM avatar Sep 17 '25 10:09 AlekseiNikiforovIBM

I have a PR out for building s390x binary wheels: https://github.com/protocolbuffers/protobuf/pull/23527

haberman avatar Sep 17 '25 15:09 haberman