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

View File

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

View File

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