Skip to content

fix(gloucester): handle communal bin cards that start with a line break - #2331

Closed
coredev-uk wants to merge 1 commit into
robbrad:masterfrom
coredev-uk:fix/gloucester-communal-bins
Closed

coredev-uk wants to merge 1 commit into
robbrad:masterfrom
coredev-uk:fix/gloucester-communal-bins

Conversation

@coredev-uk

@coredev-uk coredev-uk commented Nov 4, 2026 •

Copy link
Copy Markdown

Problem

Gloucester City Council fails for properties with communal bins:

Failed setup, will retry: Unexpected error: 'NoneType' object has no attribute 'children'

Example: Flat 1, Britannia Warehouse, The Docks, GL1 2EH (UPRN 10007323976).

The parser read the bin type with select_one("div:nth-child(1)"). That only matches a <div> that is the container's first child. Communal recycling cards put a <br/> before the bin-type <div>:

<div style="display: inline-block; font-size: 16px;">
  <br/>
  <div>Communal recycling: glass, tins, cans, plastic, paper and cardboard</div>
  ...

So nothing matched, select_one returned None, and .children raised. The first communal card (Communal household waste) has no leading <br/>, so it parses fine. The crash comes from the recycling cards after it.

Fix

Use the container's first direct <div> child, wherever it sits (find("div", recursive=False)), and take its first non-empty string as the bin type. If no type is found, the card is skipped, same as before.

Verification

Ran live against the council site with headless Chrome:

Property Before After
UPRN 10007323976, GL1 2EH (communal) AttributeError Communal household waste, Communal recycling: glass/tins/cans/plastic/paper/cardboard, Communal recycling: food
UPRN 100120479507, GL2 0RR (input.json fixture, kerbside) 2 bins 2 bins: refuse sack and recycling

Other communal flats I checked (GL1 3NE, GL1 2DJ) crashed the same way before the fix and parse after it. Kerbside flats in GL2 5AJ give the same output before and after.

Summary by CodeRabbit

  • Bug Fixes
    • Improved bin-type detection for Gloucester City Council listings by reading the card’s direct text. Listings without usable text are now skipped, helping prevent incorrect or empty bin-type results.

Communal recycling cards prefix the bin-type <div> with a <br/>, so
div:nth-child(1) matched nothing and parsing crashed with
"'NoneType' object has no attribute 'children'". Take the card's first
<div> child instead, wherever it sits.
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

Walkthrough

Gloucester bin-type extraction now reads the first stripped text string from a direct child <div>. It skips cards when the <div> is absent or contains no text.

Changes: Gloucester bin-type extraction

Layer / File(s) Summary
Read bin type from card text
uk_bin_collection/uk_bin_collection/councils/GloucesterCityCouncil.py
The extraction reads the first stripped text string from a direct child <div>. It skips cards when the <div> is absent or contains no text.

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Suggested reviewers: simoncozens

Merge Risk: Low · up to ab6f0

The parser change is mergeable with a bounded testing follow-up: add a communal-card regression test so the leading-break failure cannot silently return.

- [ ] Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Tip

🎯 Customize your risk assessments

Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.

✅ Automatic approvals, with your rules

Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.

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

@coredev-uk coredev-uk closed this Nov 4, 2026
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