Skip to content

WAB: Prevent cli update archived results for staging#2363

Open
Tschuppi81 wants to merge 3 commits intomasterfrom
feature/ogc-2978-prevent-cli-update-archived-results-for-staging
Open

WAB: Prevent cli update archived results for staging#2363
Tschuppi81 wants to merge 3 commits intomasterfrom
feature/ogc-2978-prevent-cli-update-archived-results-for-staging

Conversation

@Tschuppi81
Copy link
Contributor

WAB: Prevent cli update archived results for staging

As official_host is not set for staging, cli upload-archived-results may cause duplicates when uploading new results due to different urls.

TYPE: Feature
LINK: ogc-2978

Checklist

  • I have performed a self-review of my code
  • I considered adding a reviewer
  • I have added an upgrade hint such as data migration commands to be run
  • I have updated the PO files
  • I have added new modules to the docs
  • I made changes/features for both org and town6
  • I have updated the election_day API docs
  • I have tested my code thoroughly by hand
    • I have tested styling changes/features on different browsers
    • I have tested javascript changes/features on different browsers
    • I have tested database upgrades
    • I have tested sending mails
    • I have tested building the documentation
  • I have added tests for my changes/features
    • I am using freezegun for tests depending on date and times
    • I considered using browser tests für javascript changes/features
    • I have added/updated jest tests for d3rendering (election_day, swissvotes)

@linear
Copy link

linear bot commented Feb 24, 2026

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.24%. Comparing base (3d0b3fe) to head (76b1d67).
⚠️ Report is 3 commits behind head on master.
✅ All tests successful. No failed tests found.

Additional details and impacted files
Files with missing lines Coverage Δ
src/onegov/election_day/cli.py 81.30% <100.00%> (+0.62%) ⬆️

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3d0b3fe...76b1d67. Read the comment docs.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_host is set and if the host is localhost:8080, displaying a warning and preventing execution
  • Updated the test for update-archived-results to 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_host is 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 where official_host is NOT set. Consider adding a test case that verifies the warning is shown when official_host is 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.

Comment on lines 211 to 212
app.principal
and app.principal.official_host is None
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

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

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':

Suggested change
app.principal
and app.principal.official_host is None
not app.principal
or app.principal.official_host is None

Copilot uses AI. Check for mistakes.
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