Convert Warrington Council to use plain JSON parser#2134
Conversation
|
Caution Review failedAn error occurred during the review process. Please try again later. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@uk_bin_collection/uk_bin_collection/councils/WarringtonBoroughCouncil.py`:
- Around line 28-31: The bin_collection.get("schedule", []) call silently
defaults to an empty list when the "schedule" key is missing, which masks
upstream API changes and produces incorrect results. Instead of using a default
empty list, add explicit error checking that raises an exception (such as
KeyError or ValueError) if "schedule" is missing or malformed, allowing the
parser to fail fast and alert developers to schema drift. This change should
apply to the loop iteration over bin_collection data in the collection
processing logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: ff332c49-3121-463f-9ad8-91394121c4a5
📒 Files selected for processing (2)
uk_bin_collection/uk_bin_collection/common.pyuk_bin_collection/uk_bin_collection/councils/WarringtonBoroughCouncil.py
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@uk_bin_collection/uk_bin_collection/councils/WarringtonBoroughCouncil.py`:
- Around line 23-24: Remove the premature validation check at lines 23-24 in
WarringtonBoroughCouncil.py that attempts to validate the `schedule` variable
using `isinstance(schedule, list)` before it is defined. This check references
an undefined variable and will cause a NameError at runtime. The same validation
is already correctly implemented at lines 31-33 after the `schedule` variable is
extracted from the response, so delete the duplicate lines 23-24 entirely.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f20dfebb-d700-4514-b1fe-0de3bfdf2257
📒 Files selected for processing (1)
uk_bin_collection/uk_bin_collection/councils/WarringtonBoroughCouncil.py
| if not isinstance(schedule, list): | ||
| raise ValueError("Unexpected Warrington response: missing/invalid 'schedule'") |
There was a problem hiding this comment.
Remove premature validation that references undefined variable.
Lines 23-24 check schedule before it's defined at line 31, causing a NameError at runtime. The validation is correctly placed at lines 31-33 after schedule is extracted from the response. Delete lines 23-24 entirely.
🐛 Proposed fix
uri = f"https://www.warrington.gov.uk/bin-collections/get-jobs/{user_uprn}"
-if not isinstance(schedule, list):
- raise ValueError("Unexpected Warrington response: missing/invalid 'schedule'")
response = requests.get(uri, headers=HEADERS, timeout=30)🧰 Tools
🪛 Ruff (0.15.17)
[error] 23-23: Undefined name schedule
(F821)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@uk_bin_collection/uk_bin_collection/councils/WarringtonBoroughCouncil.py`
around lines 23 - 24, Remove the premature validation check at lines 23-24 in
WarringtonBoroughCouncil.py that attempts to validate the `schedule` variable
using `isinstance(schedule, list)` before it is defined. This check references
an undefined variable and will cause a NameError at runtime. The same validation
is already correctly implemented at lines 31-33 after the `schedule` variable is
extracted from the response, so delete the duplicate lines 23-24 entirely.
Source: Linters/SAST tools
The Warrington Council data consumer was broken. Warrington Council return formatted JSON for the API now (perhaps they changed), so this PR switches out the previous Selenium browser for a simple JSON parser.
Summary by CodeRabbit