Bugfix/swi 63 handle empty policy area#1933
Conversation
|
Is there a way to influence the converters to handle this case? |
Codecov Report❌ Patch coverage is
Additional details and impacted files
... and 107 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Yes, you can write a custom converter for the policy area format, so any values that don't conform to the format get dropped. Ideally we change the collection to accept |
Daverball
left a comment
There was a problem hiding this comment.
This is closer to what I suggested, but it's not quite there yet.
There was a problem hiding this comment.
Pull request overview
Fixes a crash in the SwissVotes /votes view when the policy_area query parameter contains empty values by introducing a dedicated policy-area URL converter/validator and adjusting the collection/form code to work with PolicyArea objects.
Changes:
- Add
PolicyAreaURL encode/decode support (dropping empty/invalid values) and use it for the/votespath converter. - Change
SwissVoteCollection.policy_areafromlist[str]tolist[PolicyArea]and update filtering + form model application accordingly. - Extend/update test suite to cover converter behavior and the “empty policy area” request scenario.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/onegov/user/test_auth.py | Adds a gitleaks:allow marker for the Yubikey secret in tests. |
| tests/onegov/swissvotes/test_views_votes.py | Adds regression test ensuring /votes doesn’t crash with an empty policy_area parameter. |
| tests/onegov/swissvotes/test_forms.py | Updates search form tests to use PolicyArea objects for policy_area. |
| tests/onegov/swissvotes/test_converters.py | Adds tests for policy-area URL encoding/decoding behavior. |
| tests/onegov/swissvotes/test_collections.py | Updates collection tests to pass/expect PolicyArea objects for policy_area. |
| src/onegov/swissvotes/path.py | Switches /votes query conversion for policy_area to a custom converter and drops empty entries. |
| src/onegov/swissvotes/models/policy_area.py | Adds from_url_param validation and __hash__ for PolicyArea. |
| src/onegov/swissvotes/forms/search.py | Ensures the form uses string values while the model uses PolicyArea objects. |
| src/onegov/swissvotes/converters.py | Introduces policy_area_converter for Morepath URL param conversion. |
| src/onegov/swissvotes/collections/votes.py | Updates filtering logic to consume PolicyArea objects directly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| filtered_policy_area = [ | ||
| p for p in policy_area if p | ||
| ] if policy_area else None |
There was a problem hiding this comment.
I don't think this step is necessary. I'm pretty sure morepath will discard any values that convert to None for list converters. Please verify. If it doesn't do that it might be necessary for the converter to raise ValueError when it doesn't see a valid PolicyArea.
SWI: Ignore empty policy area
TYPE: Bugfix
LINK: swi-63
Checklist