sentry: Fix type error in add_context.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
(cherry picked from commit 71e1b3c91b)
This commit is contained in:
Anders Kaseorg
2024-03-20 19:52:33 -07:00
committed by Tim Abbott
parent 3045cfaf22
commit c11af3aae6

View File

@@ -32,8 +32,9 @@ def add_context(event: "Event", hint: "Hint") -> Optional["Event"]:
# https://docs.sentry.io/platforms/python/guides/django/enriching-error-data/additional-data/identify-user/
event.setdefault("tags", {})
user_info = event.get("user", {})
if user_info.get("id"):
user_profile = get_user_profile_by_id(user_info["id"])
user_id = user_info.get("id")
if isinstance(user_id, str):
user_profile = get_user_profile_by_id(int(user_id))
event["tags"]["realm"] = user_info["realm"] = user_profile.realm.string_id or "root"
with override_language(settings.LANGUAGE_CODE):
# str() to force the lazy-translation to apply now,