Skip to content

Convert Warrington Council to use plain JSON parser#2134

Open
alpriest wants to merge 7 commits into
robbrad:masterfrom
alpriest:master
Open

Convert Warrington Council to use plain JSON parser#2134
alpriest wants to merge 7 commits into
robbrad:masterfrom
alpriest:master

Conversation

@alpriest

@alpriest alpriest commented Jun 16, 2026

Copy link
Copy Markdown

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

  • Updates
    • Improved Warrington Borough Council bin collection data retrieval
    • Enhanced validation of collection schedule information and date handling

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

An error occurred during the review process. Please try again later.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@alpriest alpriest mentioned this pull request Jun 16, 2026
4 tasks

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between b65502c and 0339f6b.

📒 Files selected for processing (2)
  • uk_bin_collection/uk_bin_collection/common.py
  • uk_bin_collection/uk_bin_collection/councils/WarringtonBoroughCouncil.py

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0339f6b and 927117d.

📒 Files selected for processing (1)
  • uk_bin_collection/uk_bin_collection/councils/WarringtonBoroughCouncil.py

Comment on lines +23 to +24
if not isinstance(schedule, list):
raise ValueError("Unexpected Warrington response: missing/invalid 'schedule'")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

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

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.

1 participant