From 9b3ef8b693c2b083376ac3590574373544c1fa5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 20 Oct 2015 10:35:47 +0200 Subject: [PATCH] Fix: Persist all data different from default, not just current changes We need to merge with our current data since we only might get partial data from our caller. (cherry picked from commit 7ea1578) --- src/octoprint/plugin/__init__.py | 12 ++++++++++++ src/octoprint/plugin/types.py | 11 ++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/octoprint/plugin/__init__.py b/src/octoprint/plugin/__init__.py index 84fa12b0..0cc58715 100644 --- a/src/octoprint/plugin/__init__.py +++ b/src/octoprint/plugin/__init__.py @@ -446,6 +446,18 @@ class PluginSettings(object): return path def get_all_data(self, **kwargs): + merged = kwargs.get("merged", True) + asdict = kwargs.get("asdict", True) + defaults = kwargs.get("defaults", self.defaults) + preprocessors = kwargs.get("preprocessors", self.get_preprocessors) + + kwargs.update(dict( + merged=merged, + asdict=asdict, + defaults=defaults, + preprocessors=preprocessors + )) + return self.settings.get(self._prefix_path(), **kwargs) def clean_all_data(self): diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index d2d95491..1b67436b 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -813,12 +813,17 @@ class SettingsPlugin(OctoPrintPlugin): """ import octoprint.util - if self.config_version_key in data: - del data[self.config_version_key] + # get the current data + current = self._settings.get_all_data() + + # merge our new data on top of it + new_current = octoprint.util.dict_merge(current, data) + if self.config_version_key in new_current: + del new_current[self.config_version_key] # determine diff dict that contains minimal set of changes against the # default settings - we only want to persist that, not everything - diff = octoprint.util.dict_diff(self.get_settings_defaults(), data) + diff = octoprint.util.dict_diff(self.get_settings_defaults(), new_current) version = self.get_settings_version()