Skip to content

Commit a19832b

Browse files
[3.12] gh-126489: Do not call persistent_id() for a persistent id in Python pickle (GH-126490) (GH-126516)
(cherry picked from commit 8fa4dc4)
1 parent 97ab3cf commit a19832b

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Lib/pickle.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,11 @@ def save(self, obj, save_persistent_id=True):
533533
self.framer.commit_frame()
534534

535535
# Check for persistent id (defined by a subclass)
536-
pid = self.persistent_id(obj)
537-
if pid is not None and save_persistent_id:
538-
self.save_pers(pid)
539-
return
536+
if save_persistent_id:
537+
pid = self.persistent_id(obj)
538+
if pid is not None:
539+
self.save_pers(pid)
540+
return
540541

541542
# Check the memo
542543
x = self.memo.get(id(obj))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The Python implementation of :mod:`pickle` no longer calls
2+
:meth:`pickle.Pickler.persistent_id` for the result of
3+
:meth:`!persistent_id`.

0 commit comments

Comments
 (0)