From c11af3aae632024827ffa5afc9ef3a7679acefa0 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 20 Mar 2024 19:52:33 -0700 Subject: [PATCH] sentry: Fix type error in add_context. Signed-off-by: Anders Kaseorg (cherry picked from commit 71e1b3c91bb55f6e40682e72b782908453e14364) --- zproject/sentry.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/zproject/sentry.py b/zproject/sentry.py index 7d184b4306..8d004d4539 100644 --- a/zproject/sentry.py +++ b/zproject/sentry.py @@ -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,