From 57e9f5f3fb1e46e3c2ab987df6eac694e08d1dc3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 18 Feb 2026 00:52:31 +1100 Subject: [PATCH] Prevent migration check if performing DB update operations (#11356) (#11359) * 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 (cherry picked from commit 951586a6980e43d0f05956f31ff042dcdf9936ea) Co-authored-by: Oliver --- src/backend/InvenTree/InvenTree/apps.py | 5 +++++ src/backend/InvenTree/InvenTree/tasks.py | 6 ++++++ src/backend/InvenTree/common/settings.py | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/src/backend/InvenTree/InvenTree/apps.py b/src/backend/InvenTree/InvenTree/apps.py index 34f74850a3..afb372614c 100644 --- a/src/backend/InvenTree/InvenTree/apps.py +++ b/src/backend/InvenTree/InvenTree/apps.py @@ -320,6 +320,11 @@ class InvenTreeConfig(AppConfig): if MIGRATIONS_CHECK_DONE: 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(): logger.error('INVE-W8: Database Migrations required') sys.exit(1) diff --git a/src/backend/InvenTree/InvenTree/tasks.py b/src/backend/InvenTree/InvenTree/tasks.py index 123ee4f966..531b2ace19 100644 --- a/src/backend/InvenTree/InvenTree/tasks.py +++ b/src/backend/InvenTree/InvenTree/tasks.py @@ -586,6 +586,12 @@ def update_exchange_rates(force: bool = False): Arguments: 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: from djmoney.contrib.exchange.models import Rate diff --git a/src/backend/InvenTree/common/settings.py b/src/backend/InvenTree/common/settings.py index c721d8c346..d1d8763461 100644 --- a/src/backend/InvenTree/common/settings.py +++ b/src/backend/InvenTree/common/settings.py @@ -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): """Set the value of a global setting using the provided key.""" 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['create'] = create