Skip to content

Commit

Permalink
Allow auto-loading of plugins in certain conditions (#3762)
Browse files Browse the repository at this point in the history
  • Loading branch information
SchrodingersGat authored Oct 8, 2022
1 parent 6774058 commit c146256
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions InvenTree/InvenTree/ready.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,8 +25,6 @@ def canAppAccessDatabase(allow_test=False):
'flush',
'loaddata',
'dumpdata',
'makemigrations',
'migrate',
'check',
'shell',
'createsuperuser',
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion InvenTree/plugin/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit c146256

Please sign in to comment.