From 33ea9c34597eaca802fc4d411c4f69fa6a0f080a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 21 Jun 2015 12:09:38 +0200 Subject: [PATCH] Fix: Software Update config could contain circular reference Caused by a wrong variable usage. Fixed the usage and added a migration step that fixes the circular reference if it exists. Bumping configuration version to 2. Fixes #946 --- .../plugins/softwareupdate/__init__.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/octoprint/plugins/softwareupdate/__init__.py b/src/octoprint/plugins/softwareupdate/__init__.py index 4d91dd83..fd3bd0d1 100644 --- a/src/octoprint/plugins/softwareupdate/__init__.py +++ b/src/octoprint/plugins/softwareupdate/__init__.py @@ -92,7 +92,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._version_cache_ttl = self._settings.get_int(["cache_ttl"]) * 60 def get_settings_version(self): - return 1 + return 2 def on_settings_migrate(self, target, current=None): if current is None: @@ -111,7 +111,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, deletables=["current"] else: deletables=[] - octoprint_check = self._clean_settings_check("octoprint", configured_checks, self.get_settings_defaults()["checks"]["octoprint"], delete=deletables, save=False) + octoprint_check = self._clean_settings_check("octoprint", octoprint_check, self.get_settings_defaults()["checks"]["octoprint"], delete=deletables, save=False) # and the hooks update_check_hooks = self._plugin_manager.get_hooks("octoprint.plugin.softwareupdate.check_config") @@ -132,6 +132,19 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin, self._clean_settings_check(key, settings_check, data, delete=deletables, save=False) + elif current == 1: + configured_checks = self._settings.get(["checks"], incl_defaults=False) + if configured_checks is None: + return + + if "octoprint" in configured_checks and "octoprint" in configured_checks["octoprint"]: + # that's a circular reference, back to defaults + dummy_defaults = dict(plugins=dict()) + dummy_defaults["plugins"][self._identifier] = dict(checks=dict()) + dummy_defaults["plugins"][self._identifier]["checks"]["octoprint"] = None + self._settings.set(["checks", "octoprint"], None, defaults=dummy_defaults) + self._settings.save() + def _clean_settings_check(self, key, data, defaults, delete=None, save=True): if delete is None: delete = []