Skip to content

Skip voter-file rows whose login ID another voter already holds instead of failing the upload - #569

Closed
benadida wants to merge 1 commit into
masterfrom
fix/voter-upload-duplicate-login-id
Closed

benadida wants to merge 1 commit into
masterfrom
fix/voter-upload-duplicate-login-id

Conversation

@benadida

@benadida benadida commented Nov 23, 2026 •

Copy link
Copy Markdown
Owner

Error

The helios.tasks.voter_file_process background task fails with:

psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "helios_voter_voter_login_id_69b7ffa9_uniq"
DETAIL:  Key (voter_login_id, election_id)=(…) already exists.
  File "/app/helios/tasks.py", line 150, in voter_file_process
  File "/app/helios/models.py", line 929, in process
    Voter.register_user_in_election(user, self.election)
  File "/app/helios/models.py", line 1008, in register_user_in_election
    voter.save()

Frequency: 2 failed uploads in the last 14 days (Nov 11 and Nov 22), both on this same frame. These are the only voter_file_process failures in that window.

Root cause

In VoterFile.process(), a row for an auth-system voter (GitHub, Google, etc.) only checks for an existing voter linked to the same User (get_by_election_and_user). register_user_in_election then sets voter_login_id = user.user_id. If another voter in the election already has that login ID, the insert hits the (election, voter_login_id) unique constraint. That other voter could be a password voter with the same ID, or a user from a different auth system with the same username. In the production failure, the new row was an auth-system user with no email on file.

Voters are created one at a time in shuffled order with no surrounding transaction. So when the task fails, the election is left with a random subset of the file loaded, and processing_finished_at is never set.

Fix

Before registering, also check Voter.get_by_election_and_voter_id(election, user.user_id), which the password branch already does. A row whose login ID is already taken is treated as already present and counted in num_skipped, like other duplicate rows.

Tests

  • Added ElectionModelTests.test_add_voters_file_skips_login_id_taken_by_another_voter_type. It loads a password voter, then uploads a file with a GitHub row using the same ID plus one new GitHub voter. Without the fix the test fails with the same IntegrityError; with the fix it passes.
  • Full suite: uv run python manage.py test: 338 tests, OK (1 skipped).

Datadog

service:helios-main ("path=helios.tasks.voter_file_process state=FAILED" OR "helios_voter_voter_login_id_69b7ffa9_uniq")

Generated by Claude Code


Devin Review

A voter upload row for an auth-system user (e.g. GitHub) only checked for an
existing voter linked to the same user. If a voter of another type (a password
voter, or a user from another auth system with the same username) already held
that login ID, the insert hit the (election, voter_login_id) unique constraint
and the voter_file_process task failed partway, leaving the list half-loaded.
Treat such rows as already present and count them as skipped, like the
password branch already does.

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

@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: 2 flags

Not posted on this PR by your GitHub settings — view them in Devin Review. (Configure)

Devin Review

@benadida

Copy link
Copy Markdown
Owner Author

let's not do this. If we get this error again we'll consider it.

@benadida benadida closed this Nov 29, 2026
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