fix: NorthYorkshire - find HTML data dynamically in AJAX response#1949
fix: NorthYorkshire - find HTML data dynamically in AJAX response#1949InertiaUK wants to merge 1 commit intorobbrad:masterfrom
Conversation
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
🧹 Nitpick comments (1)
uk_bin_collection/uk_bin_collection/councils/NorthYorkshire.py (1)
31-39: Tighten HTML payload detection to the expected container
"<div"is a broad match and may select the wrong command payload if multiple HTML fragments appear. Prefer matching the known marker (e.g.,upcoming-collection) so failure mode stays deterministic.Proposed refactor
- html_data = None - for item in bin_data: - if isinstance(item, dict) and isinstance(item.get("data"), str) and "<div" in item["data"]: - html_data = item["data"] - break - - if not html_data: - raise ValueError("No HTML bin data found in API response") + html_data = next( + ( + item.get("data") + for item in bin_data + if isinstance(item, dict) + and isinstance(item.get("data"), str) + and "upcoming-collection" in item["data"] + ), + None, + ) + + if html_data is None: + raise ValueError("No upcoming-collection HTML found in API response")🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@uk_bin_collection/uk_bin_collection/councils/NorthYorkshire.py` around lines 31 - 39, The current loop in NorthYorkshire.py that picks html_data from bin_data uses a broad "<div" check and can select the wrong fragment; update the detection logic in that loop (the block that assigns html_data) to look for the specific marker string (e.g., "upcoming-collection") inside item.get("data") instead of "<div" so the parser (BeautifulSoup(html_data, ...)) always receives the expected container; keep the existing isinstance checks and the subsequent ValueError if html_data is not found.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@uk_bin_collection/uk_bin_collection/councils/NorthYorkshire.py`:
- Around line 31-39: The current loop in NorthYorkshire.py that picks html_data
from bin_data uses a broad "<div" check and can select the wrong fragment;
update the detection logic in that loop (the block that assigns html_data) to
look for the specific marker string (e.g., "upcoming-collection") inside
item.get("data") instead of "<div" so the parser (BeautifulSoup(html_data, ...))
always receives the expected container; keep the existing isinstance checks and
the subsequent ValueError if html_data is not found.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 2c552d3b-ccb6-4f22-af02-80d67d532513
📒 Files selected for processing (1)
uk_bin_collection/uk_bin_collection/councils/NorthYorkshire.py
The AJAX endpoint at /ajax returns a list of command objects. The HTML bin data was at index [1] but has shifted to index [2] — the response now has a CSS stylesheet object at [1] instead.
Changed the parser to search the list for the first item where data is a string containing HTML, instead of hardcoding the index. This is resilient to future index shifts.
Tested with UPRN 10093091235 in Selby.
Summary by CodeRabbit