From a4e159315f0d2a35c3ff90acdcf3a1d41046109f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20H=C3=B6ning?= Date: Tue, 8 Aug 2023 17:21:38 +0200 Subject: [PATCH] fix: stop making app.reports a property - when FLEXMEASURES_PLUGINS is set, app.reports.update fails otherwise MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Nicolas Höning --- flexmeasures/app.py | 4 ++-- flexmeasures/utils/plugin_utils.py | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/flexmeasures/app.py b/flexmeasures/app.py index 64e745ff6..8f0cd046d 100644 --- a/flexmeasures/app.py +++ b/flexmeasures/app.py @@ -133,7 +133,7 @@ def create( # noqa C901 ) # use copy to avoid mutating app.reporters app.data_generators["scheduler"] = schedulers - # deprecation of app.reporters + # deprecated: app.reporters and app.schedulers app.reporters = reporters app.schedulers = schedulers @@ -143,7 +143,7 @@ def get_reporters(): ) return app.data_generators["reporter"] - setattr(app, "reporters", property(get_reporters)) + setattr(app, "reporters", get_reporters()) # add auth policy diff --git a/flexmeasures/utils/plugin_utils.py b/flexmeasures/utils/plugin_utils.py index 4e9af8817..f9510f51e 100644 --- a/flexmeasures/utils/plugin_utils.py +++ b/flexmeasures/utils/plugin_utils.py @@ -16,7 +16,7 @@ from flexmeasures.utils.coding_utils import get_classes_module -def register_plugins(app: Flask): +def register_plugins(app: Flask): # noqa: C901 """ Register FlexMeasures plugins as Blueprints. This is configured by the config setting FLEXMEASURES_PLUGINS. @@ -113,13 +113,14 @@ def register_plugins(app: Flask): plugin_reporters = get_classes_module(module.__name__, Reporter) plugin_schedulers = get_classes_module(module.__name__, Scheduler) - # for legacy, we keep reporters and schedulers - app.reporters.update(plugin_reporters) - app.schedulers.update(plugin_schedulers) - # add DataGenerators - app.data_generators["scheduler"].update(plugin_schedulers) - app.data_generators["reporter"].update(plugin_reporters) + # for legacy, we still maintain app.reporters and app.schedulers + if plugin_reporters: + app.data_generators["reporter"].update(plugin_reporters) + app.reporters.update(plugin_reporters) + if plugin_schedulers: + app.data_generators["scheduler"].update(plugin_schedulers) + app.schedulers.update(plugin_schedulers) app.config["LOADED_PLUGINS"][plugin_name] = plugin_version app.logger.info(f"Loaded plugins: {app.config['LOADED_PLUGINS']}")