From c73e7ae1784c2d2b4912f13809c92fb3fea8be8a Mon Sep 17 00:00:00 2001 From: Erik Montnemery Date: Mon, 22 Jul 2024 15:41:55 +0200 Subject: [PATCH] Handle integration with missing dependencies (#122386) --- homeassistant/bootstrap.py | 8 +++++++- tests/test_bootstrap.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/homeassistant/bootstrap.py b/homeassistant/bootstrap.py index f4cfc8c87c8..a16fd1fa3e9 100644 --- a/homeassistant/bootstrap.py +++ b/homeassistant/bootstrap.py @@ -906,7 +906,13 @@ async def _async_resolve_domains_to_setup( await asyncio.gather(*resolve_dependencies_tasks) for itg in integrations_to_process: - for dep in itg.all_dependencies: + try: + all_deps = itg.all_dependencies + except RuntimeError: + # Integration.all_dependencies raises RuntimeError if + # dependencies could not be resolved + continue + for dep in all_deps: if dep in domains_to_setup: continue domains_to_setup.add(dep) diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 8eb411fc4ee..153bb9a07f7 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -1329,6 +1329,34 @@ async def test_bootstrap_dependencies( ) +@pytest.mark.parametrize("load_registries", [False]) +async def test_bootstrap_dependency_not_found( + hass: HomeAssistant, + caplog: pytest.LogCaptureFixture, +) -> None: + """Test setup when an integration has missing dependencies.""" + mock_integration( + hass, + MockModule("good_integration", dependencies=[]), + ) + # Simulate an integration with missing dependencies. While a core integration + # can't have missing dependencies thanks to checks by hassfest, there's no such + # guarantee for custom integrations. + mock_integration( + hass, + MockModule("bad_integration", dependencies=["hahaha_crash_and_burn"]), + ) + + assert await bootstrap.async_from_config_dict( + {"good_integration": {}, "bad_integration": {}}, hass + ) + + assert "good_integration" in hass.config.components + assert "bad_integration" not in hass.config.components + + assert "Unable to resolve dependencies for bad_integration" in caplog.text + + async def test_pre_import_no_requirements(hass: HomeAssistant) -> None: """Test pre-imported and do not have any requirements.""" pre_imports = [