Handle more caching exception pathways (#6678)

This commit is contained in:
Oliver 2024-03-12 14:53:02 +11:00 committed by GitHub
parent 60f3e849e7
commit c185a267da
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 6 deletions

View File

@ -226,9 +226,12 @@ class BaseInvenTreeSetting(models.Model):
""" """
cache_key = f'BUILD_DEFAULT_VALUES:{str(cls.__name__)}' cache_key = f'BUILD_DEFAULT_VALUES:{str(cls.__name__)}'
try:
if InvenTree.helpers.str2bool(cache.get(cache_key, False)): if InvenTree.helpers.str2bool(cache.get(cache_key, False)):
# Already built default values # Already built default values
return return
except Exception:
pass
try: try:
existing_keys = cls.objects.filter(**kwargs).values_list('key', flat=True) existing_keys = cls.objects.filter(**kwargs).values_list('key', flat=True)
@ -251,7 +254,10 @@ class BaseInvenTreeSetting(models.Model):
) )
pass pass
try:
cache.set(cache_key, True, timeout=3600) cache.set(cache_key, True, timeout=3600)
except Exception:
pass
def _call_settings_function(self, reference: str, args, kwargs): def _call_settings_function(self, reference: str, args, kwargs):
"""Call a function associated with a particular setting. """Call a function associated with a particular setting.

View File

@ -34,7 +34,10 @@ def currency_code_default():
code = 'USD' # pragma: no cover code = 'USD' # pragma: no cover
# Cache the value for a short amount of time # Cache the value for a short amount of time
try:
cache.set('currency_code_default', code, 30) cache.set('currency_code_default', code, 30)
except Exception:
pass
return code return code

View File

@ -748,7 +748,11 @@ def check_user_role(user, role, permission):
break break
# Save result to cache # Save result to cache
try:
cache.set(key, result, timeout=3600) cache.set(key, result, timeout=3600)
except Exception:
pass
return result return result