]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.7] bpo-34621: backwards-compatible pickle UUID with is_safe=unknown (GH-14834)
authorTal Einat <taleinat+github@gmail.com>
Sun, 4 Aug 2019 19:26:32 +0000 (22:26 +0300)
committerGitHub <noreply@github.com>
Sun, 4 Aug 2019 19:26:32 +0000 (22:26 +0300)
This is a fix for a bug introduced in the original implementation of this for 3.7.

Lib/uuid.py
Misc/NEWS.d/next/Library/2019-08-04-22-06-54.bpo-34621.E2EWkw.rst [new file with mode: 0644]

index 26faa1accd09e66120945f612e7fd8a42c78b720..b1abfe315d562b88e81fb4968bca3e0a80d98fca 100644 (file)
@@ -205,12 +205,14 @@ class UUID:
         self.__dict__['is_safe'] = is_safe
 
     def __getstate__(self):
-        state = self.__dict__
+        state = self.__dict__.copy()
         if self.is_safe != SafeUUID.unknown:
             # is_safe is a SafeUUID instance.  Return just its value, so that
             # it can be un-pickled in older Python versions without SafeUUID.
-            state = state.copy()
             state['is_safe'] = self.is_safe.value
+        else:
+            # omit is_safe when it is "unknown"
+            del state['is_safe']
         return state
 
     def __setstate__(self, state):
diff --git a/Misc/NEWS.d/next/Library/2019-08-04-22-06-54.bpo-34621.E2EWkw.rst b/Misc/NEWS.d/next/Library/2019-08-04-22-06-54.bpo-34621.E2EWkw.rst
new file mode 100644 (file)
index 0000000..1128a2f
--- /dev/null
@@ -0,0 +1,2 @@
+Fixed unpickle-ability in older Python versions (<3.7) of UUID objects with
+``is_safe`` set to ``SafeUUID.unknown``.