Skip to content

fix: UttlesfordDistrictCouncil - house number prefix match in dropdown#1994

Closed
InertiaUK wants to merge 1 commit into
robbrad:masterfrom
InertiaUK:fix/UttlesfordDistrictCouncil-address-match
Closed

fix: UttlesfordDistrictCouncil - house number prefix match in dropdown#1994
InertiaUK wants to merge 1 commit into
robbrad:masterfrom
InertiaUK:fix/UttlesfordDistrictCouncil-address-match

Conversation

@InertiaUK
Copy link
Copy Markdown
Contributor

@InertiaUK InertiaUK commented May 1, 2026

select_by_visible_text fails when the dropdown text includes the street name (e.g. "72, Birchanger Lane") but only the house number is provided as paon.

Now tries exact match first, then iterates options matching by house number prefix (handles "72," and "72 " patterns).

Testing: Verified with CM23 5QF / 72 — returns 12 bins.

Summary by CodeRabbit

  • Bug Fixes
    • Improved address selection matching to support case-insensitive searches and prefix-style matching
    • Enhanced error handling with clearer feedback when addresses cannot be found in available options

…ch in dropdown

select_by_visible_text fails when the dropdown text includes the street
name (e.g. "72, Birchanger Lane") but only the house number is provided.
Now tries exact match first, then iterates options matching by house
number prefix.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

📝 Walkthrough

Walkthrough

Enhanced address selection in Uttlesford District Council module by implementing a multi-step matching strategy: first attempts exact dropdown text match, then falls back to case-insensitive prefix matching, with explicit error handling for unmatched addresses.

Changes

Cohort / File(s) Summary
Address Selection Logic
uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.py
Improved address matching with fallback mechanism: attempts exact match first, then case-insensitive prefix matching, raising ValueError if address not found in dropdown.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A dropdown match, now swift and wise,
First tries exact, then prefix tries,
Case-insensitive, graceful and keen—
The finest address search we've seen!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and accurately summarizes the main change: fixing house number prefix matching in the Uttlesford address selection dropdown.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

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

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.67%. Comparing base (ea4cd4c) to head (5c23bbd).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1994   +/-   ##
=======================================
  Coverage   86.67%   86.67%           
=======================================
  Files           9        9           
  Lines        1141     1141           
=======================================
  Hits          989      989           
  Misses        152      152           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.py`:
- Around line 68-71: The except block around
drop_down_values.select_by_visible_text(str(user_paon)) is too broad; import
selenium.common.exceptions.NoSuchElementException and change the except
Exception: to except NoSuchElementException: so only missing-option cases are
suppressed (other exceptions will propagate); update the imports at the top to
include NoSuchElementException and keep the matched=True logic as-is.
🪄 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: 127f449b-e450-401e-a4e7-3b9542a709eb

📥 Commits

Reviewing files that changed from the base of the PR and between d661bf1 and 5c23bbd.

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

Comment on lines +68 to +71
try:
drop_down_values.select_by_visible_text(str(user_paon))
matched = True
except Exception:
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 | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

# First, check the file exists and get its structure
head -100 uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.py

Repository: robbrad/UKBinCollectionData

Length of output: 3726


🏁 Script executed:

# Check the imports section specifically
head -20 uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.py

Repository: robbrad/UKBinCollectionData

Length of output: 741


🏁 Script executed:

# Look at lines around 68-71 to see the exact code
sed -n '60,85p' uk_bin_collection/uk_bin_collection/councils/UttlesfordDistrictCouncil.py

Repository: robbrad/UKBinCollectionData

Length of output: 1157


🏁 Script executed:

# Search for other uses of select_by_visible_text in the codebase to see how exceptions are handled
rg "select_by_visible_text" -A 3 -B 1

Repository: robbrad/UKBinCollectionData

Length of output: 4605


🏁 Script executed:

# Search for any existing uses of NoSuchElementException in the codebase
rg "NoSuchElementException" .

Repository: robbrad/UKBinCollectionData

Length of output: 2668


🏁 Script executed:

# Check if any files import from selenium.common.exceptions
rg "selenium.common.exceptions" .

Repository: robbrad/UKBinCollectionData

Length of output: 1629


Narrow the except clause to NoSuchElementException.

The current except Exception: on line 71 catches all exceptions — including WebDriver errors, timeouts, and stale element references — and silently falls into the prefix loop instead of surfacing real failures. select_by_visible_text() raises selenium.common.exceptions.NoSuchElementException when no option matches; catching only that exception aligns with the project-wide pattern shown in AngusCouncil.py, ChichesterDistrictCouncil.py, SevenoaksDistrictCouncil.py, and others.

Add the import:

+from selenium.common.exceptions import NoSuchElementException
 from selenium.webdriver.common.by import By

Narrow the except clause:

-            except Exception:
+            except NoSuchElementException:
🧰 Tools
🪛 Ruff (0.15.12)

[warning] 71-71: Do not catch blind exception: Exception

(BLE001)

🤖 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/UttlesfordDistrictCouncil.py`
around lines 68 - 71, The except block around
drop_down_values.select_by_visible_text(str(user_paon)) is too broad; import
selenium.common.exceptions.NoSuchElementException and change the except
Exception: to except NoSuchElementException: so only missing-option cases are
suppressed (other exceptions will propagate); update the imports at the top to
include NoSuchElementException and keep the matched=True logic as-is.

@robbrad
Copy link
Copy Markdown
Owner

robbrad commented May 2, 2026

Included in May 2026 Release (PR #1992). Closing.

@robbrad robbrad closed this May 2, 2026
@robbrad robbrad mentioned this pull request May 2, 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.

2 participants