From 729c85646ad6bb8fd38119279fc21cf3f590c2b8 Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 6 Nov 2024 22:25:14 +0200 Subject: [PATCH] [3.12] gh-126489: Do not call persistent_id() for a persistent id in Python pickle (GH-126490) (cherry picked from commit 8fa4dc4ba8646c59f945f2451c53e2919f066065) Co-authored-by: Serhiy Storchaka --- Lib/pickle.py | 9 +++++---- .../2024-11-06-13-41-38.gh-issue-126489.toaf-0.rst | 3 +++ 2 files changed, 8 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2024-11-06-13-41-38.gh-issue-126489.toaf-0.rst diff --git a/Lib/pickle.py b/Lib/pickle.py index 01c1a102794d57..ea5f1c5dc36c91 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -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)) diff --git a/Misc/NEWS.d/next/Library/2024-11-06-13-41-38.gh-issue-126489.toaf-0.rst b/Misc/NEWS.d/next/Library/2024-11-06-13-41-38.gh-issue-126489.toaf-0.rst new file mode 100644 index 00000000000000..8a6573cdea7b42 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-11-06-13-41-38.gh-issue-126489.toaf-0.rst @@ -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`.