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
{{ message }}
Repository navigation
Python pickler unable to pickle object the native pickler can #120380
Traceback (most recent call last):
File "bug.py", line 24, in <module>
pickler.dump(data)
File "/pickle.py", line 487, in dumpself.save(obj)
File "/pickle.py", line 560, in save
f(self, obj) # Call unbound method with explicit self^^^^^^^^^^^^
File "/pickle.py", line 932, in save_listself._batch_appends(obj)
File "/pickle.py", line 956, in _batch_appends
save(x)
File "/pickle.py", line 603, in saveself.save_reduce(obj=obj, *rv)
File "/pickle.py", line 692, in save_reduce
save(args)
File "/pickle.py", line 560, in save
f(self, obj) # Call unbound method with explicit self^^^^^^^^^^^^
File "/pickle.py", line 887, in save_tuple
save(element)
File "/pickle.py", line 560, in save
f(self, obj) # Call unbound method with explicit self^^^^^^^^^^^^
File "/pickle.py", line 842, in save_picklebufferself.save_bytearray(m.tobytes())
File "/pickle.py", line 821, in save_bytearrayself.memoize(obj)
File "/pickle.py", line 508, in memoizeassertid(obj) notinself.memo
^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
The ZeroCopyBytearray buffer appears to need the following implementation (it's actually in Lib/test/pickletester) but I confirmed that the issue remains but only if the buffer is empty (otherwise it's fine). The implementation is roughly
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).
Activity
picnixz commentedon Jun 12, 2024
aisk commentedon Jun 12, 2024
picnixz commentedon Jun 12, 2024
picnixz commentedon Jun 12, 2024
The ZeroCopyBytearray buffer appears to need the following implementation (it's actually in
Lib/test/pickletester) but I confirmed that the issue remains but only if the buffer is empty (otherwise it's fine). The implementation is roughlySo, the
__reduce_ex__method makes more things than what you provided in your example, but it does not fix the issue at all.EDIT: I'm investigating the issue in picnixz@a8c1464
apmorton commentedon Jun 12, 2024
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.
picnixz commentedon Jun 12, 2024
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).
gh-120380: fix Python implementation of `pickle.Pickler` for `bytes` …
pythongh-120380: fix Python implementation of `pickle.Pickler` for `b…
pythongh-120380: fix Python implementation of `pickle.Pickler` for `b…
[3.13] gh-120380: fix Python implementation of `pickle.Pickler` for `…
[3.12] gh-120380: fix Python implementation of `pickle.Pickler` for `…
encukou commentedon Jun 27, 2024
Thank you @apmorton for the report, and @picnixz for the fix!
pythongh-120380: fix Python implementation of `pickle.Pickler` for `b…
pythongh-120380: fix Python implementation of `pickle.Pickler` for `b…
pythongh-120380: fix Python implementation of `pickle.Pickler` for `b…