[3.12] gh-126489: Do not call persistent_id() for a persistent id in Python pickle (GH-126490) (GH-126516)

(cherry picked from commit 8fa4dc4ba8)
This commit is contained in:
Serhiy Storchaka 2024-11-06 23:11:37 +02:00 committed by GitHub
parent 97ab3cf374
commit a19832bfbf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 4 deletions

View file

@ -533,10 +533,11 @@ def save(self, obj, save_persistent_id=True):
self.framer.commit_frame()
# Check for persistent id (defined by a subclass)
pid = self.persistent_id(obj)
if pid is not None and save_persistent_id:
self.save_pers(pid)
return
if save_persistent_id:
pid = self.persistent_id(obj)
if pid is not None:
self.save_pers(pid)
return
# Check the memo
x = self.memo.get(id(obj))

View file

@ -0,0 +1,3 @@
The Python implementation of :mod:`pickle` no longer calls
:meth:`pickle.Pickler.persistent_id` for the result of
:meth:`!persistent_id`.