Skip to content

Commit

Permalink
[3.12] pythongh-126489: Do not call persistent_id() for a persistent …
Browse files Browse the repository at this point in the history
…id in Python pickle (pythonGH-126490)

(cherry picked from commit 8fa4dc4)

Co-authored-by: Serhiy Storchaka <[email protected]>
  • Loading branch information
serhiy-storchaka committed Nov 6, 2024
1 parent 97ab3cf commit 729c856
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Lib/pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
@@ -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`.

0 comments on commit 729c856

Please sign in to comment.