-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Python pickler unable to pickle object the native pickler can #120380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
The ZeroCopyBytearray buffer appears to need the following implementation (it's actually in class ZeroCopyBytearray(bytearray):
def __reduce_ex__(self, protocol):
if protocol >= 5:
return type(self)._reconstruct, (pickle.PickleBuffer(self),), None
else:
return type(self)._reconstruct, (bytes(self),)
@classmethod
def _reconstruct(cls, obj):
with memoryview(obj) as m:
obj = m.obj
if type(obj) is cls:
# Zero-copy
return obj
else:
return cls(obj) So, the EDIT: I'm investigating the issue in picnixz@a8c1464 |
Correct, I minimized the example to only the relevant parts for reproduction. The issue only happens if you use protocol 5 and end up with two objects having different IDs produce a PickleBuffer with the same underlying buffer ID. |
Yes, the issue is that this specific test case is not covered (I've added one and I'll try to fix it), which is why we did not see the issue (by specific case, I mean the two different instances that are empty, not that it still works if I use the same non-empty buffer values). |
…and `bytearray` objects in protocol version 5. (GH-120422)
…ytes` and `bytearray` objects in protocol version 5. (pythonGH-120422) (cherry picked from commit 7595e67) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…ytes` and `bytearray` objects in protocol version 5. (pythonGH-120422) (cherry picked from commit 7595e67) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…bytes` and `bytearray` objects in protocol version 5. (GH-120422) (GH-120832) gh-120380: fix Python implementation of `pickle.Pickler` for `bytes` and `bytearray` objects in protocol version 5. (GH-120422) (cherry picked from commit 7595e67) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…bytes` and `bytearray` objects in protocol version 5. (GH-120422) (GH-120833) gh-120380: fix Python implementation of `pickle.Pickler` for `bytes` and `bytearray` objects in protocol version 5. (GH-120422) (cherry picked from commit 7595e67) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
…ytes` and `bytearray` objects in protocol version 5. (pythonGH-120422)
…ytes` and `bytearray` objects in protocol version 5. (pythonGH-120422)
…ytes` and `bytearray` objects in protocol version 5. (pythonGH-120422)
Bug report
Bug description:
CPython versions tested on:
3.11
Operating systems tested on:
Linux
Linked PRs
pickle.Pickler
forbytes
andbytearray
objects in protocol version 5. #120422pickle.Pickler
forbytes
andbytearray
objects in protocol version 5. (GH-120422) #120832pickle.Pickler
forbytes
andbytearray
objects in protocol version 5. (GH-120422) #120833The text was updated successfully, but these errors were encountered: