8000 fix: Add user id in django integration · etherscan-io/sentry-python@c1e0ba0 · GitHub
[go: up one dir, main page]

Skip to content

Commit c1e0ba0

Browse files
committed
fix: Add user id in django integration
1 parent 8784592 commit c1e0ba0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

sentry_sdk/integrations/django/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ def _set_user_info(request, event):
189189
if user is None or not is_authenticated(user):
190190
return
191191

192+
if "id" not in user_info:
193+
try:
194+
user_info["id"] = str(user.pk)
195+
except Exception:
196+
pass
197+
192198
if "email" not in user_info:
193199
try:
194200
user_info["email"] = user.email

tests/integrations/django/test_basic.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,11 @@ def test_user_captured(sentry_init, client, capture_events):
9393

9494
event, = events
9595

96-
assert event["user"] == {"email": "lennon@thebeatles.com", "username": "john"}
96+
assert event["user"] == {
97+
"email": "lennon@thebeatles.com",
98+
"username": "john",
99+
"id": "1",
100+
}
97101

98102

99103
def test_404(sentry_init, client):

0 commit comments

Comments
 (0)
0