WAB: Prevent cli update archived results for staging#2363
WAB: Prevent cli update archived results for staging#2363Tschuppi81 wants to merge 3 commits intomasterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files
... and 3 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR adds validation to the update-archived-results CLI command to prevent it from running on staging environments where official_host is not configured. This prevents duplicate archived result entries that could occur when URLs differ between staging and production.
Changes:
- Added validation logic in the CLI to check if
official_hostis set and if the host islocalhost:8080, displaying a warning and preventing execution - Updated the test for
update-archived-resultsto verify the new validation behavior - Fixed import formatting in the test file to align with codebase conventions
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/onegov/election_day/cli.py |
Added validation to prevent update-archived-results from running when official_host is not set or when using localhost |
tests/onegov/election_day/test_cli.py |
Updated test to set official_host, verify warning message appears with default host, and verify command works with explicit host/scheme parameters; minor import formatting fix |
Comments suppressed due to low confidence (2)
src/onegov/election_day/cli.py:217
- There is a double space between "later" and "may" in this error message.
'staging. Uploading results later may create '
tests/onegov/election_day/test_cli.py:454
- The test coverage for the new validation logic is incomplete. The test only verifies the case where
official_hostis set but the command is run with the default localhost host. According to the PR description, the main use case is preventing the command from running on staging environments whereofficial_hostis NOT set. Consider adding a test case that verifies the warning is shown whenofficial_hostis None (not set in the principal configuration).
result = (run_command(
cfg_path,
'govikon',
[
'update-archived-results',
]
))
assert result.exit_code == 0
assert 'Official host is not set!' in result.stdout
assert session.query(ArchivedResult).count() == 0
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
src/onegov/election_day/cli.py
Outdated
| app.principal | ||
| and app.principal.official_host is None |
There was a problem hiding this comment.
This condition has incorrect operator precedence and will cause an AttributeError if app.principal is None and host != 'localhost:8080'. Due to Python's operator precedence, the expression is evaluated as ((app.principal and app.principal.official_host is None) or host == 'localhost:8080').
When app.principal is None, the first part (None and ...) evaluates to None (falsy), so if host != 'localhost:8080', the entire condition is False and execution continues past line 226. However, at line 228 and beyond, the code will likely fail because it expects app.principal to exist.
The condition should check for app.principal is None first before accessing app.principal.official_host. Consider: if not app.principal or app.principal.official_host is None or host == 'localhost:8080':
| app.principal | |
| and app.principal.official_host is None | |
| not app.principal | |
| or app.principal.official_host is None |
WAB: Prevent cli update archived results for staging
As
official_hostis not set for staging, cliupload-archived-resultsmay cause duplicates when uploading new results due to different urls.TYPE: Feature
LINK: ogc-2978
Checklist