diff --git a/src/octoprint/plugin/types.py b/src/octoprint/plugin/types.py index caabeed4..d285173c 100644 --- a/src/octoprint/plugin/types.py +++ b/src/octoprint/plugin/types.py @@ -718,7 +718,7 @@ class SettingsPlugin(OctoPrintPlugin): def on_settings_save(self, data): old_flag = self._settings.get_boolean(["sub", "some_flag"]) - super(MySettingsPlugin, self).on_settings_save(data) + octoprint.plugin.SettingsPlugin.on_settings_save(self, data) new_flag = self._settings.get_boolean(["sub", "some_flag"]) if old_flag != new_flag: diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 7bba8a02..187ff460 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -26,6 +26,8 @@ import octoprint.util @api.route("/settings", methods=["GET"]) def getSettings(): + logger = logging.getLogger(__name__) + s = settings() connectionOptions = get_connection_options() @@ -118,7 +120,7 @@ def getSettings(): for name in gcode_scripts: data["scripts"]["gcode"][name] = s.loadScript("gcode", name, source=True) - def process_plugin_result(name, plugin, result): + def process_plugin_result(name, result): if result: if not "plugins" in data: data["plugins"] = dict() @@ -126,9 +128,17 @@ def getSettings(): del result["__enabled"] data["plugins"][name] = result - octoprint.plugin.call_plugin(octoprint.plugin.SettingsPlugin, - "on_settings_load", - callback=process_plugin_result) + for plugin in octoprint.plugin.plugin_manager().get_implementations(octoprint.plugin.SettingsPlugin): + try: + result = plugin.on_settings_load() + process_plugin_result(plugin._identifier, result) + except TypeError: + logger.warn("Could not load settings for plugin {name} ({version}) since it called super(...)".format(name=plugin._plugin_name, version=plugin._plugin_version)) + logger.warn("in a way which has issues due to OctoPrint's dynamic reloading after plugin operations.") + logger.warn("Please contact the plugin's author and ask to update the plugin to use a direct call like") + logger.warn("octoprint.plugin.SettingsPlugin.on_settings_load(self) instead.") + except: + logger.exception("Could not load settings for plugin {name} ({version})".format(version=plugin._plugin_version, name=plugin._plugin_name)) return jsonify(data) @@ -137,6 +147,8 @@ def getSettings(): @restricted_access @admin_permission.require(403) def setSettings(): + logger = logging.getLogger(__name__) + if not "application/json" in request.headers["Content-Type"]: return make_response("Expected content-type JSON", 400) @@ -235,8 +247,15 @@ def setSettings(): for plugin in octoprint.plugin.plugin_manager().get_implementations(octoprint.plugin.SettingsPlugin): plugin_id = plugin._identifier if plugin_id in data["plugins"]: - plugin.on_settings_save(data["plugins"][plugin_id]) - + try: + plugin.on_settings_save(data["plugins"][plugin_id]) + except TypeError: + logger.warn("Could not save settings for plugin {name} ({version}) since it called super(...)".format(name=plugin._plugin_name, version=plugin._plugin_version)) + logger.warn("in a way which has issues due to OctoPrint's dynamic reloading after plugin operations.") + logger.warn("Please contact the plugin's author and ask to update the plugin to use a direct call like") + logger.warn("octoprint.plugin.SettingsPlugin.on_settings_save(self, data) instead.") + except: + logger.exception("Could not save settings for plugin {name} ({version})".format(version=plugin._plugin_version, name=plugin._plugin_name)) if s.save(): eventManager().fire(Events.SETTINGS_UPDATED)