protobuf
protobuf copied to clipboard
Regression: Python FromString(bytearray()) broken on upb
What version of protobuf and what language are you using? Version: git main and 4.21.7 Language: Python upb
What operating system (Linux, Windows, ...) and version? Linux
What did you do?
python -c 'from google.protobuf import timestamp_pb2; timestamp_pb2.Timestamp.FromString(bytearray())'
What did you expect to see The program should run without error.
What did you see instead?
Traceback (most recent call last):
File "<string>", line 1, in <module>
TypeError: expected bytes, bytearray found
Workarounds
- Install a 3.* version of the python package
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python- Use a memoryview:
with memoryview(byte_array) as mv:
ts = timestamp_pb2.Timestamp.FromString(mv)
Other than bytearray, it may also be useful to add a regression test for memoryview (which currently works)