From 0cb762d6b2f46e8617a8e4af130750904cd76ede Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 3 Jun 2024 21:38:47 +1000 Subject: [PATCH] Global Cache Fix (#7393) * Adjust situations in which cache is disabled - Prevent cache when running a number of housekeeping commands * Add 'spectacular' to list of excluded commands * Generate codes as list - Ensure consistent ordering (for CI) * Debug currency codes list * Bump API version --- src/backend/InvenTree/InvenTree/api_version.py | 6 ++++-- src/backend/InvenTree/InvenTree/cache.py | 10 +++------- src/backend/InvenTree/InvenTree/ready.py | 1 + src/backend/InvenTree/common/currency.py | 11 +++++++---- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/backend/InvenTree/InvenTree/api_version.py b/src/backend/InvenTree/InvenTree/api_version.py index e6c00a36a18a..47264d2649e0 100644 --- a/src/backend/InvenTree/InvenTree/api_version.py +++ b/src/backend/InvenTree/InvenTree/api_version.py @@ -1,14 +1,16 @@ """InvenTree API version information.""" # InvenTree API version -INVENTREE_API_VERSION = 203 +INVENTREE_API_VERSION = 204 """Increment this API version number whenever there is a significant change to the API that any clients need to know about.""" INVENTREE_API_TEXT = """ +v204 - 2024-06-03 : https://github.com/inventree/InvenTree/pull/7393 + - Fixes previous API update which resulted in inconsistent ordering of currency codes v203 - 2024-06-03 : https://github.com/inventree/InvenTree/pull/7390 - - Adjust default currency codes + - Currency codes are now configurable as a run-time setting v202 - 2024-05-27 : https://github.com/inventree/InvenTree/pull/7343 - Adjust "required" attribute of Part.category field to be optional diff --git a/src/backend/InvenTree/InvenTree/cache.py b/src/backend/InvenTree/InvenTree/cache.py index 241ff1f4e6d3..89765f5e80d4 100644 --- a/src/backend/InvenTree/InvenTree/cache.py +++ b/src/backend/InvenTree/InvenTree/cache.py @@ -45,13 +45,9 @@ def is_global_cache_enabled(): return False # The cache should not be used during certain operations - if any(( - InvenTree.ready.isRunningBackup(), - InvenTree.ready.isRunningMigrations(), - InvenTree.ready.isRebuildingData(), - InvenTree.ready.isImportingData(), - InvenTree.ready.isInTestMode(), - )): + if not InvenTree.ready.canAppAccessDatabase( + allow_test=False, allow_plugins=False, allow_shell=True + ): logger.info('Global cache bypassed for this operation') return False diff --git a/src/backend/InvenTree/InvenTree/ready.py b/src/backend/InvenTree/InvenTree/ready.py index b8ebfb6e0a22..41b3058fc868 100644 --- a/src/backend/InvenTree/InvenTree/ready.py +++ b/src/backend/InvenTree/InvenTree/ready.py @@ -114,6 +114,7 @@ def canAppAccessDatabase( 'wait_for_db', 'makemessages', 'compilemessages', + 'spectactular', ] if not allow_shell: diff --git a/src/backend/InvenTree/common/currency.py b/src/backend/InvenTree/common/currency.py index 542f81d1fc8b..c77549c5509b 100644 --- a/src/backend/InvenTree/common/currency.py +++ b/src/backend/InvenTree/common/currency.py @@ -68,20 +68,23 @@ def currency_codes() -> list: codes = codes.split(',') - valid_codes = set() + valid_codes = [] for code in codes: code = code.strip().upper() + if code in valid_codes: + continue + if code in CURRENCIES: - valid_codes.add(code) + valid_codes.append(code) else: logger.warning(f"Invalid currency code: '{code}'") if len(valid_codes) == 0: - valid_codes = set(currency_codes_default_list().split(',')) + valid_codes = list(currency_codes_default_list().split(',')) - return list(valid_codes) + return valid_codes def currency_code_mappings() -> list: