From 8bcdad6a8fc7a06804aad9811b269988964517e4 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 20 Nov 2021 03:29:32 +0100 Subject: [PATCH] make startup more failsafe --- InvenTree/InvenTree/settings.py | 1 + InvenTree/plugin/plugins.py | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/InvenTree/InvenTree/settings.py b/InvenTree/InvenTree/settings.py index 20291fe59f..732b4a5131 100644 --- a/InvenTree/InvenTree/settings.py +++ b/InvenTree/InvenTree/settings.py @@ -889,6 +889,7 @@ INTEGRATION_PLUGIN_GLOBALSETTING = {} INTEGRATION_APPS_LOADING = True # Marks if apps were reloaded yet INTEGRATION_PLUGINS_RELOADING = False INTEGRATION_APPS_PATHS = [] # Holds all added plugin_paths +INTEGRATION_STARTUP_ERRORS = {} # Holds discovering errors # Test settings PLUGIN_TESTING = get_setting('PLUGIN_TESTING', TESTING) # used to force enable everything plugin diff --git a/InvenTree/plugin/plugins.py b/InvenTree/plugin/plugins.py index 0822e412f3..1732dd641c 100644 --- a/InvenTree/plugin/plugins.py +++ b/InvenTree/plugin/plugins.py @@ -41,6 +41,17 @@ def get_modules(pkg, recursive: bool = False): context[name] = module except AppRegistryNotReady: pass + except Exception as error: + # this 'protects' against malformed plugin modules by more or less silently failing + # TODO log + + # make sure the registry is set up + if 'discovery' not in settings.INTEGRATION_STARTUP_ERRORS: + settings.INTEGRATION_STARTUP_ERRORS['discovery'] = [] + + # add error to stack + settings.INTEGRATION_STARTUP_ERRORS['discovery'].append({name: str(error)}) + return [v for k, v in context.items()]