Repository navigation
Show an error for a duplicate trustee email instead of 500ing - #566
Merged
Merged
Conversation
Adding a trustee whose email is already a trustee of the election hit the (election, email) unique constraint and raised IntegrityError. Check first and re-show the form with an error and the submitted values. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QuQvo1opV1c3G9Hf22qGjf
Contributor
There was a problem hiding this comment.
🔍 Devin Review: 1 flag
Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Error
POST /helios/elections/<uuid>/trustees/newreturned 500:Frequency: 3 times in the past 24h on vote.heliosvoting.org (Nov 17, 18:10 UTC), one election admin resubmitting the form for the same trustee within a few seconds.
Root cause
Trusteehasunique_together = ('election', 'email'), butnew_trusteesaves without checking, so adding a trustee whose email is already a trustee of that election (a double submit, a retry, or a typo-for-existing) hits the database constraint.Fix
Check for an existing trustee with that email first. If there is one, re-show the "New Trustee" form with an error message and the submitted name/email filled in, instead of raising.
Tests
Added
NewTrusteeViewTests(adding a trustee works; a duplicate email returns 200 with the error and doesn't create a second trustee). The duplicate test fails withIntegrityErrorwithout the fix. Full suite:uv run python manage.py test— 336 tests OK (1 skipped).Datadog
service:helios-main "trustees/new" status=500/service:helios-main "helios_trustee_election_id"Generated by Claude Code