Repository navigation
Don't 500 on the voter email page for an election with no voters #567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1805,6 +1805,9 @@ def voters_email(request, election): | |
| election_url = get_election_url(election) | ||
| election_vote_url = get_election_govote_url(election) | ||
|
|
||
| # the preview shows how a voter logs in; the election may have no voters yet | ||
| sample_voter = voter or election.voter_set.first() | ||
|
|
||
| default_subject = render_text_template('email/%s_subject.txt' % template, { | ||
| 'custom_subject': "<SUBJECT>" | ||
| }) | ||
|
|
@@ -1818,7 +1821,7 @@ def voters_email(request, election): | |
| 'name': '<VOTER_NAME>', | ||
| 'voter_login_id': '<VOTER_LOGIN_ID>', | ||
| 'voter_password': '<VOTER_PASSWORD>', | ||
| 'voter_type' : election.voter_set.all()[0].voter_type, | ||
| 'voter_type' : sample_voter.voter_type if sample_voter else None, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Empty-election preview names a None account With no voters, Learn moreThe preview renders an email template with a placeholder voter. Voting and simple emails interpolate that voter's authentication type in their login instructions. On an election without voters, the new fallback passes Example: A frozen open-registration election has zero voters. Its admin opens the default voting email preview and reads “Log in with your None account,” although a future recipient will see their actual login method. Recommended fix: Give the empty-election preview a distinct generic login instruction in both voting email templates, or pass a valid representative auth system selected from Was this helpful? React with 👍 or 👎 to provide feedback.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed: with no voters, the vote/simple preview's Generated by Claude Code |
||
| 'election' : election} | ||
| }) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 New test breaks required Python indentation
The new
test_voters_email_accessible_with_no_votersmethod uses four-space indentation, contrary to the repository's required two-space Python indentation.Learn more
The repository's indentation rule requires two spaces throughout Python files. The new test uses four spaces per indentation level, matching the surrounding tests but not that explicit rule. Changing only this method to two spaces would leave its class inconsistent.
Example: The method declaration starts with four spaces and its statements start with eight, where the stated convention calls for two and four spaces.
Recommended fix: Reconcile the mandatory indentation rule with the existing test-file convention before applying the change consistently; do not reindent only the new method if it makes the class harder to read.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
helios/tests.pyuses 4-space indentation throughout, so the new test matches the class it sits in. Reindenting just this method would make the class inconsistent, and reindenting the whole file is out of scope for this fix. Leaving it as is.Generated by Claude Code