]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-126489: Do not call persistent_id() for a persistent id in Python pickle...
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 6 Nov 2024 21:11:37 +0000 (23:11 +0200)
committerGitHub <noreply@github.com>
Wed, 6 Nov 2024 21:11:37 +0000 (21:11 +0000)
(cherry picked from commit 8fa4dc4ba8646c59f945f2451c53e2919f066065)

Lib/pickle.py
Misc/NEWS.d/next/Library/2024-11-06-13-41-38.gh-issue-126489.toaf-0.rst [new file with mode: 0644]

index 01c1a102794d571f1af7d3cc275d144695142404..ea5f1c5dc36c915e106328b4498297c0464df2de 100644 (file)
@@ -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 (file)
index 0000000..8a6573c
--- /dev/null
@@ -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`.