From c146256170c55b0675e3a4601ca6f7199d659122 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sun, 9 Oct 2022 09:07:51 +1100 Subject: [PATCH] Allow auto-loading of plugins in certain conditions (#3762) Ref: https://github.com/matmair/InvenTree/commit/52af1966941ce564bae485988c40b8161d6f201e --- InvenTree/InvenTree/ready.py | 10 +++++++--- InvenTree/plugin/apps.py | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/InvenTree/InvenTree/ready.py b/InvenTree/InvenTree/ready.py index f7a319a92d..81a050321d 100644 --- a/InvenTree/InvenTree/ready.py +++ b/InvenTree/InvenTree/ready.py @@ -13,7 +13,7 @@ def isImportingData(): return 'loaddata' in sys.argv -def canAppAccessDatabase(allow_test=False): +def canAppAccessDatabase(allow_test: bool = False, allow_plugins: bool = False): """Returns True if the apps.py file can access database records. There are some circumstances where we don't want the ready function in apps.py @@ -25,8 +25,6 @@ def canAppAccessDatabase(allow_test=False): 'flush', 'loaddata', 'dumpdata', - 'makemigrations', - 'migrate', 'check', 'shell', 'createsuperuser', @@ -43,6 +41,12 @@ def canAppAccessDatabase(allow_test=False): # Override for testing mode? excluded_commands.append('test') + if not allow_plugins: + excluded_commands.extend([ + 'makemigrations', + 'migrate', + ]) + for cmd in excluded_commands: if cmd in sys.argv: return False diff --git a/InvenTree/plugin/apps.py b/InvenTree/plugin/apps.py index bb0c8cfb94..bd56e05709 100644 --- a/InvenTree/plugin/apps.py +++ b/InvenTree/plugin/apps.py @@ -27,7 +27,7 @@ class PluginAppConfig(AppConfig): def ready(self): """The ready method is extended to initialize plugins.""" if settings.PLUGINS_ENABLED: - if not canAppAccessDatabase(allow_test=True): + if not canAppAccessDatabase(allow_test=True, allow_plugins=True): logger.info("Skipping plugin loading sequence") # pragma: no cover else: logger.info('Loading InvenTree plugins')