diff --git a/django_evaluation/utils.py b/django_evaluation/utils.py index b5809927..301875af 100644 --- a/django_evaluation/utils.py +++ b/django_evaluation/utils.py @@ -1,6 +1,7 @@ """Collection of utility functions.""" from __future__ import annotations +import logging import json import threading @@ -43,9 +44,15 @@ def sync_mail_users(refresh_itervall: int = 3600, oneshot: bool = False) -> None email__isnull=True ) ] - cache.set( - "user_email_info", mark_safe(json.dumps(user_info)), refresh_itervall + 10 - ) + try: + cache.set( + "user_email_info", + mark_safe(json.dumps(user_info)), + refresh_itervall + 10, + ) + except Exception as error: + logger = logging.getLogger("freva-web") + logger.error("Could not add user email info to cache: %s", error) if oneshot is True: break time.sleep(refresh_itervall) diff --git a/history/templatetags/dialogtags.py b/history/templatetags/dialogtags.py index 4fa0aaff..02b1735b 100644 --- a/history/templatetags/dialogtags.py +++ b/history/templatetags/dialogtags.py @@ -1,3 +1,4 @@ +import logging import json from django import template @@ -35,7 +36,13 @@ def mailfield(is_guest): """Extract the email information from users that have been logged in.""" data = mark_safe(json.dumps([])) if not is_guest: - data = cache.get("user_email_info") or mark_safe( + try: + data = cache.get("user_email_info") + except Exception as error: + data = None + logger = logging.getLogger("freva-web") + logger.error("Could not add user email info to cache: %s", error) + data = data or mark_safe( json.dumps( [ {