From: Serhiy Storchaka Date: Wed, 6 Nov 2024 21:11:37 +0000 (+0200) Subject: [3.12] gh-126489: Do not call persistent_id() for a persistent id in Python pickle... X-Git-Tag: v3.12.8~101 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a19832bfbffcca0c224434a877f671137bc87137;p=thirdparty%2FPython%2Fcpython.git [3.12] gh-126489: Do not call persistent_id() for a persistent id in Python pickle (GH-126490) (GH-126516) (cherry picked from commit 8fa4dc4ba8646c59f945f2451c53e2919f066065) --- diff --git a/Lib/pickle.py b/Lib/pickle.py index 01c1a102794d..ea5f1c5dc36c 100644 --- a/Lib/pickle.py +++ b/Lib/pickle.py @@ -533,10 +533,11 @@ class _Pickler: 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 000000000000..8a6573cdea7b --- /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`.