Skip to content

Treat a session voter that no longer exists as logged out instead of 500ing - #564

Merged
benadida merged 1 commit into
masterfrom
fix/stale-voter-session
Nov 29, 2026
Merged

benadida merged 1 commit into
masterfrom
fix/stale-voter-session

Conversation

@benadida

@benadida benadida commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Error

GET /helios/elections/<uuid>/view on a private election returned a 500:

File "/app/helios/security.py", line 123, in election_view_wrapper
File "/app/helios/security.py", line 160, in user_can_see_election
File "/app/helios/security.py", line 47, in get_voter
    voter = Voter.objects.get(id=request.session['CURRENT_VOTER_ID'])
helios.models.Voter.DoesNotExist: Voter matching query does not exist.

Frequency: 1 occurrence in the last 24h (2026-11-13 19:15 UTC), on helios-main. Low volume, but deterministic: anyone whose session holds the id of a voter that has since been deleted gets a 500 on every private-election page guarded by election_view until the session expires.

Root cause

get_voter() trusts CURRENT_VOTER_ID in the session (set by password voter login) and does Voter.objects.get(...). If the admin removed that voter, for example by deleting and re-uploading the voter list, the lookup raises.

Fix

  • Look the voter up with filter(...).first().
  • If it's gone, drop CURRENT_VOTER_ID from the session and fall through to the usual user-based lookup. On a private election the voter is sent to the password voter login page like any logged-out visitor.

Added ElectionBlackboxTests.test_private_election_view_with_deleted_session_voter. It fails with Voter.DoesNotExist without the fix and passes with it. uv run python manage.py test helios (293 tests) and helios_auth both pass locally.

Datadog

service:helios-main "in get_voter" (or service:helios-main "Voter matching query does not exist")


Generated by Claude Code


Devin Review

…500ing

A voter removed from an election after logging in kept their voter id in the
session, and get_voter() raised Voter.DoesNotExist on the next private
election page. Look the voter up with filter().first() and drop the stale
session entry so they're sent to the voter login page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QuQvnySS4szpAhhKDrzDVG

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@benadida
benadida merged commit 7b6ca64 into master Nov 29, 2026
2 checks passed
@benadida
benadida deleted the fix/stale-voter-session branch November 29, 2026 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants