You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any object that allows us to call `memoryview(serialized)` to access a string of
bytes using the buffer interface.
However, I had trouble with a custom type that implements the buffer interface. I reproduced it with an array which also implements the buffer interface in the example above.
From reading the source it appears that serialized needs to be one of {memoryview, bytearray, bytes}, but does not support arbitrary buffer interface types. I checked with version 3.19.2 (before upb) and did not have the same issue there.
What version of protobuf and what language are you using?
Python protobuf 5.28.2. I believe this affects all versions after the upb migration.
What operating system (Linux, Windows, ...) and version?
Linux (Amazon Linux 2)
What runtime / compiler are you using (e.g., python version or gcc version)
Python 3.12
What did you do?
What did you expect to see
The program should run without error.
What did you see instead?
Workaround
Wrap the argument to
MergeFromString
in amemoryview()
.The documentation says that
MergeFromString()
should work onHowever, I had trouble with a custom type that implements the buffer interface. I reproduced it with an
array
which also implements the buffer interface in the example above.From reading the source it appears that
serialized
needs to be one of {memoryview
,bytearray
,bytes
}, but does not support arbitrary buffer interface types. I checked with version 3.19.2 (before upb) and did not have the same issue there.Would it be a good idea to to instead use
PyMemoryView_FromObject
(with a NULL check) instead? That seems closer to the old Python-native logic and the documentation.Note: this is similar to #16691 (issue #15911) that added support for
bytearray
's, but that is still not as general as any buffer protocol type.The text was updated successfully, but these errors were encountered: