From f86bd4dd6b35fa4aa72e680fd662cf7fac57ddb9 Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 19 Oct 2021 20:59:14 +0200 Subject: [PATCH] catch db not loaded --- InvenTree/plugin/apps.py | 57 ++++++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/InvenTree/plugin/apps.py b/InvenTree/plugin/apps.py index 5a16e0735d..ee9bf3bef6 100644 --- a/InvenTree/plugin/apps.py +++ b/InvenTree/plugin/apps.py @@ -5,6 +5,7 @@ from typing import OrderedDict from django.apps import AppConfig, apps from django.conf import settings +from django.db.utils import OperationalError, ProgrammingError class PluginConfig(AppConfig): @@ -14,33 +15,37 @@ class PluginConfig(AppConfig): from common.models import InvenTreeSetting plugins = settings.INTEGRATION_PLUGINS.items() - # if plugin settings are enabled enhance the settings - if settings.TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_SETTING'): - for slug, plugin in plugins: - if plugin.mixin_enabled('settings'): - plugin_setting = plugin.settingspatterns - settings.INTEGRATION_PLUGIN_SETTING[slug] = plugin_setting + try: + # if plugin settings are enabled enhance the settings + if settings.TESTING or InvenTreeSetting.get_setting('ENABLE_PLUGINS_SETTING'): + for slug, plugin in plugins: + if plugin.mixin_enabled('settings'): + plugin_setting = plugin.settingspatterns + settings.INTEGRATION_PLUGIN_SETTING[slug] = plugin_setting - # Add to settings dir - InvenTreeSetting.GLOBAL_SETTINGS.update(plugin_setting) + # Add to settings dir + InvenTreeSetting.GLOBAL_SETTINGS.update(plugin_setting) - # if plugin apps are enabled - if settings.TESTING or ((not settings.INTEGRATION_APPS_LOADED) and InvenTreeSetting.get_setting('ENABLE_PLUGINS_APP')): - settings.INTEGRATION_APPS_LOADED = True # ensure this section will not run again - apps_changed = False + # if plugin apps are enabled + if settings.TESTING or ((not settings.INTEGRATION_APPS_LOADED) and InvenTreeSetting.get_setting('ENABLE_PLUGINS_APP')): + settings.INTEGRATION_APPS_LOADED = True # ensure this section will not run again + apps_changed = False - # add them to the INSTALLED_APPS - for slug, plugin in plugins: - if plugin.mixin_enabled('app'): - plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(settings.BASE_DIR).parts) - if plugin_path not in settings.INSTALLED_APPS: - settings.INSTALLED_APPS += [plugin_path] - apps_changed = True + # add them to the INSTALLED_APPS + for slug, plugin in plugins: + if plugin.mixin_enabled('app'): + plugin_path = '.'.join(pathlib.Path(plugin.path).relative_to(settings.BASE_DIR).parts) + if plugin_path not in settings.INSTALLED_APPS: + settings.INSTALLED_APPS += [plugin_path] + apps_changed = True - # if apps were changed reload - # TODO this is a bit jankey to be honest - if apps_changed: - apps.app_configs = OrderedDict() - apps.apps_ready = apps.models_ready = apps.loading = apps.ready = False - apps.clear_cache() - apps.populate(settings.INSTALLED_APPS) + # if apps were changed reload + # TODO this is a bit jankey to be honest + if apps_changed: + apps.app_configs = OrderedDict() + apps.apps_ready = apps.models_ready = apps.loading = apps.ready = False + apps.clear_cache() + apps.populate(settings.INSTALLED_APPS) + except (OperationalError, ProgrammingError): + # Exception if the database has not been migrated yet + pass