Skip to content

Commit

Permalink
Global Cache Fix (#7393)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
SchrodingersGat authored Jun 3, 2024
1 parent e83feb9 commit 0cb762d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/backend/InvenTree/InvenTree/api_version.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 3 additions & 7 deletions src/backend/InvenTree/InvenTree/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions src/backend/InvenTree/InvenTree/ready.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def canAppAccessDatabase(
'wait_for_db',
'makemessages',
'compilemessages',
'spectactular',
]

if not allow_shell:
Expand Down
11 changes: 7 additions & 4 deletions src/backend/InvenTree/common/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0cb762d

Please sign in to comment.