Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
models: Force the translated role into a translated string.
Alex Vandiver012113c54264
diff --git a/zerver/logging_handlers.py b/zerver/logging_handlers.pyindex 24316b8f735..6086ef9f86a 100644--- a/zerver/logging_handlers.py+++ b/zerver/logging_handlers.py@@ -9,6 +9,7 @@ from urllib.parse import SplitResultfrom django.conf import settingsfrom django.http import HttpRequest+from django.utils.translation import override as override_languagefrom django.views.debug import get_exception_reporter_filterfrom sentry_sdk import capture_exceptionfrom typing_extensions import Protocol, runtime_checkable@@ -46,7 +47,10 @@ def add_request_metadata(report: Dict[str, Any], request: HttpRequest) -> None:else:user_full_name = user_profile.full_nameuser_email = user_profile.email- user_role = user_profile.get_role_name()+ with override_language(settings.LANGUAGE_CODE):+ # str() to force the lazy-translation to apply now,+ # since it won't serialize into the worker queue.+ user_role = str(user_profile.get_role_name())except Exception:# Unexpected exceptions here should be handled gracefullytraceback.print_exc()diff --git a/zproject/sentry.py b/zproject/sentry.pyindex 8d615c2ce42..9d29270d1fa 100644--- a/zproject/sentry.py+++ b/zproject/sentry.py@@ -1,6 +1,7 @@from typing import TYPE_CHECKING, Optionalimport sentry_sdk+from django.utils.translation import override as override_languagefrom sentry_sdk.integrations import Integrationfrom sentry_sdk.integrations.django import DjangoIntegrationfrom sentry_sdk.integrations.logging import ignore_logger@@ -21,13 +22,18 @@ def add_context(event: 'Event', hint: 'Hint') -> Optional['Event']:# Ignore GeneratorExit, KeyboardInterrupt, and SystemExit exceptionsif not isinstance(exc_value, Exception):return None+ from django.conf import settings+from zerver.models import get_user_profile_by_idwith capture_internal_exceptions():user_info = event.get("user", {})if user_info.get("id"):user_profile = get_user_profile_by_id(user_info["id"])user_info["realm"] = user_profile.realm.string_id or 'root'- user_info["role"] = user_profile.get_role_name()+ with override_language(settings.LANGUAGE_CODE):+ # str() to force the lazy-translation to apply now,+ # since it won't serialize into json for Sentry otherwise+ user_info["role"] = str(user_profile.get_role_name())return eventdef setup_sentry(dsn: Optional[str], *integrations: Integration) -> None: