Skip to content

fix(common): import holidays lazily so a broken install can't stop the integration - #2345

Merged
robbrad merged 1 commit into
masterfrom
claude/lazy-holidays-import
Nov 14, 2026
Merged

robbrad merged 1 commit into
masterfrom
claude/lazy-holidays-import

Conversation

@robbrad

@robbrad robbrad commented Nov 14, 2026

Copy link
Copy Markdown
Owner

Why

#2335: after a Home Assistant core update the integration fails to load at all:

Setup failed for custom integration 'uk_bin_collection': Unable to import component:
No module named 'holidays.calendars.hebrew'

What's actually going on

holidays.calendars.hebrew exists in the holidays version this project locks (0.103), and our code only does a plain import holidays. A missing submodule inside a package that is otherwise present is the signature of a half-upgraded holidays install in the user's Home Assistant container (HA core and HACS both install it). So the root cause is in their environment, and I can't fix it from here.

What I can fix is the blast radius. Only one scraper (Vale of White Horse) uses holidays, yet common.py imported it at module level and every scraper imports common. One bad package therefore took down all ~350 councils, including the ones that never touch it.

Change

Import holidays inside is_holiday() instead. Now a broken install only affects that one council, and everyone else keeps working.

Existing is_holiday tests patch holidays.country_holidays on the module object, so they're unaffected (they still pass).

Test

test_holidays_import_is_lazy.py runs in a subprocess (so the deliberately broken package can't leak into other tests) with a fake holidays package on the path that raises the exact error from the report. It asserts that common and collect_data still import, and that only is_holiday() fails.

I confirmed it reproduces the problem: against master's common.py it fails with ModuleNotFoundError: No module named 'holidays.calendars.hebrew' at common.py:10, the same traceback as the report. With the change it passes.

Test plan

I used Targets rather than Fixes because the user's own install still needs repairing (restart / rebuild the container, or pip install --force-reinstall holidays inside it). This change just stops one bad package taking everything else down.

Targets #2335



Generated by Claude Code

…e integration

Only one scraper (Vale of White Horse) uses the `holidays` package, but
common.py imported it at module level and every scraper imports common. A
broken `holidays` install, as in #2335 ("No module named
'holidays.calendars.hebrew'" after a Home Assistant core update, which is the
signature of a half-upgraded package), therefore stopped the whole integration
from loading for all ~350 councils.

Import it inside is_holiday() instead, so such a failure now only affects that
one council. A subprocess test puts a deliberately broken `holidays` package on
the path and checks that `common` and `collect_data` still import; it fails on
the old code with the same traceback as the report.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015MaCS29izthZp2dwtvLwf4
@coderabbitai

coderabbitai Bot commented Nov 14, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a03527e6-d6e9-4dd1-9dc0-2b591222fa78
Commits

Reviewing files that changed from the base of the PR and between 0d1b26a and 4bc0855.

Files selected for processing: 2

  • uk_bin_collection/tests/test_holidays_import_is_lazy.py
  • uk_bin_collection/uk_bin_collection/common.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.57%. Comparing base (0d1b26a) to head (4bc0855).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2345   +/-   ##
=======================================
  Coverage   83.57%   83.57%           
=======================================
  Files          43       43           
  Lines        3380     3380           
=======================================
  Hits         2825     2825           
  Misses        555      555           

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

@robbrad
robbrad merged commit e844e9a into master Nov 14, 2026
14 of 15 checks passed
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