From a2ea9448c677706d6318eaa71101f08df7604eb9 Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Sun, 4 Aug 2019 22:26:32 +0300 Subject: [PATCH] [3.7] bpo-34621: backwards-compatible pickle UUID with is_safe=unknown (GH-14834) This is a fix for a bug introduced in the original implementation of this for 3.7. --- Lib/uuid.py | 6 ++++-- .../next/Library/2019-08-04-22-06-54.bpo-34621.E2EWkw.rst | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2019-08-04-22-06-54.bpo-34621.E2EWkw.rst diff --git a/Lib/uuid.py b/Lib/uuid.py index 26faa1accd09..b1abfe315d56 100644 --- a/Lib/uuid.py +++ b/Lib/uuid.py @@ -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 index 000000000000..1128a2fb4459 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-08-04-22-06-54.bpo-34621.E2EWkw.rst @@ -0,0 +1,2 @@ +Fixed unpickle-ability in older Python versions (<3.7) of UUID objects with +``is_safe`` set to ``SafeUUID.unknown``. -- 2.47.3