DashboardsentrySentry UserEmail.objects.get(email__iex…

Sentry UserEmail.objects.get(email__iexact=) raises MultipleObjectsReturned

Category: gotcha
Confidence: 1.00
ID: 019d79f0-e3f9-7e37-8432-9e26d8e3e319
Project ID: 702228c8-56bc-4694-8d5a-174ac2f29105
Cross-project: No
Recalled in other projects: 0
Source session: (none)
Created: 2026-07-30 15:46:04
Updated: 2026-07-30 15:46:04

Content

Multiple Sentry users can share the same email address via UserEmail. Using .get(email__iexact=email) without filtering by user raises MultipleObjectsReturned. Fix: use .filter(email__iexact=email).order_by('-is_verified', 'id').first() to prefer verified emails and get deterministic results. The existing codebase pattern in identity.py always filters by both user and email to avoid this.

Move to: