protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Regression: Python FromString(bytearray()) broken on upb

Open ajasmin opened this issue 3 years ago • 0 comments

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

  1. Install a 3.* version of the python package
  2. export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
  3. 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)

ajasmin avatar Oct 14 '22 06:10 ajasmin