2
0
mirror of https://github.com/inventree/InvenTree.git synced 2026-02-19 13:18:03 +00:00

Prevent migration check if performing DB update operations (#11356)

* Prevent migration check if performing DB update operations

* Prevent settings write during data imports

* Prevent exchange rate update during migration processes

* Allow exchange rate updates during tests or shell session
This commit is contained in:
Oliver
2026-02-18 00:19:58 +11:00
committed by GitHub
parent 1cc1f059c8
commit 951586a698
3 changed files with 18 additions and 0 deletions

View File

@@ -331,6 +331,11 @@ class InvenTreeConfig(AppConfig):
if MIGRATIONS_CHECK_DONE: if MIGRATIONS_CHECK_DONE:
return return
# Exit early if we are not in a state where we can access the database,
# otherwise we might end up in a deadlock situation
if not InvenTree.ready.canAppAccessDatabase():
return
if not InvenTree.tasks.check_for_migrations(): if not InvenTree.tasks.check_for_migrations():
# Detect if this an empty database - if so, start with a fresh migration # Detect if this an empty database - if so, start with a fresh migration
if ( if (

View File

@@ -587,6 +587,12 @@ def update_exchange_rates(force: bool = False):
Arguments: Arguments:
force: If True, force the update to run regardless of the last update time force: If True, force the update to run regardless of the last update time
""" """
from InvenTree.ready import canAppAccessDatabase
# Do not update exchange rates if we cannot access the database
if not canAppAccessDatabase(allow_test=True, allow_shell=True):
return
try: try:
from djmoney.contrib.exchange.models import Rate from djmoney.contrib.exchange.models import Rate

View File

@@ -44,6 +44,13 @@ def get_global_setting(key, backup_value=None, environment_key=None, **kwargs):
def set_global_setting(key, value, change_user=None, create=True, **kwargs): def set_global_setting(key, value, change_user=None, create=True, **kwargs):
"""Set the value of a global setting using the provided key.""" """Set the value of a global setting using the provided key."""
from common.models import InvenTreeSetting from common.models import InvenTreeSetting
from InvenTree.ready import canAppAccessDatabase
if not canAppAccessDatabase(allow_shell=True, allow_test=True):
logger.warning(
f'Cannot set global setting "{key}" - database is not accessible'
)
return False
kwargs['change_user'] = change_user kwargs['change_user'] = change_user
kwargs['create'] = create kwargs['create'] = create