From 9f80aefcc92fb3fc1d2197a5e564395d2a32b887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 3 Apr 2018 16:56:59 +0200 Subject: [PATCH] thaw_frozendict should be fully recursive So far it was only deep-diving into frozendicts, not dicts (which might contain frozendicts). In principle we probably should also dive into tuples and lists and other containers, but in our current application we don't put frozendicts into those so let's not overdo it. --- src/octoprint/util/__init__.py | 2 +- tests/util/test_misc.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/octoprint/util/__init__.py b/src/octoprint/util/__init__.py index 892a31782..7a2467044 100644 --- a/src/octoprint/util/__init__.py +++ b/src/octoprint/util/__init__.py @@ -979,7 +979,7 @@ def thaw_frozendict(obj): # only true love can thaw a frozen dict letitgo = dict() for key, value in obj.items(): - if isinstance(value, frozendict.frozendict): + if isinstance(value, (dict, frozendict.frozendict)): letitgo[key] = thaw_frozendict(value) else: letitgo[key] = copy.deepcopy(value) diff --git a/tests/util/test_misc.py b/tests/util/test_misc.py index f07b087f4..b0bd8b98d 100644 --- a/tests/util/test_misc.py +++ b/tests/util/test_misc.py @@ -52,6 +52,7 @@ class MiscTestCase(unittest.TestCase): (frozendict(a=1, b=2, c=frozendict(c1=1, c2=2)), dict(a=1, b=2, c=dict(c1=1, c2=2))), (dict(a=1, b=2, c=3), dict(a=1, b=2, c=3)), (dict(a=1, b=2, c=frozendict(c1=1, c2=2)), dict(a=1, b=2, c=dict(c1=1, c2=2))), + (dict(a=1, b=2, c=dict(c1=1, c2=2, c3=frozendict(c11=11, c12=12))), dict(a=1, b=2, c=dict(c1=1, c2=2, c3=dict(c11=11, c12=12)))) ) @ddt.unpack def test_unfreeze_frozendict(self, input, expected):