From 3bed8bbbd89d711f27d5dadfb63b45d6e6770f74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 22 Feb 2022 20:46:19 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20settings=20save?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Saving of whole dicts was not working, especially for plugins, due to bugs in the has_path and the set_by_path functions. --- src/octoprint/settings.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 95fdc8471..dce92e003 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -618,7 +618,9 @@ class HierarchicalChainMap: else: current = self._chainmap - return self._path_to_key(path) in current + key = self._path_to_key(path) + prefix = key + _CHAINMAP_SEP + return key in current or any(map(lambda x: x.startswith(prefix), current.keys())) def get_by_path(self, path, only_local=False, only_defaults=False, merged=False): if only_defaults: @@ -656,14 +658,17 @@ class HierarchicalChainMap: return result def set_by_path(self, path, value): - current = self._chainmap + current = self._chainmap.maps[0] key = self._path_to_key(path) # delete any subkeys subkeys_start = key + _CHAINMAP_SEP + to_delete = [] for k in current.keys(): if k.startswith(subkeys_start): - del current[key] + to_delete.append(k) + for k in to_delete: + del current[k] if isinstance(value, dict): current.update(self._flatten(value, key))