1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Always set up after dependencies if they are scheduled to be loaded (#141593)

* Always setup after dependencies

* Add comment
This commit is contained in:
Artur Pragacz
2025-04-01 16:28:29 +02:00
committed by GitHub
parent 78338f161f
commit c4f0d9d2fa
2 changed files with 34 additions and 12 deletions

View File

@@ -213,17 +213,24 @@ async def _async_process_dependencies(
if dep not in hass.config.components
}
after_dependencies_tasks: dict[str, asyncio.Future[bool]] = {}
to_be_loaded = hass.data.get(DATA_SETUP_DONE, {})
# We don't want to just wait for the futures from `to_be_loaded` here.
# We want to ensure that our after_dependencies are always actually
# scheduled to be set up, as if for whatever reason they had not been,
# we would deadlock waiting for them here.
for dep in integration.after_dependencies:
if (
dep not in dependencies_tasks
and dep in to_be_loaded
and dep not in hass.config.components
):
after_dependencies_tasks[dep] = to_be_loaded[dep]
dependencies_tasks[dep] = setup_futures.get(dep) or create_eager_task(
async_setup_component(hass, dep, config),
name=f"setup {dep} as after dependency of {integration.domain}",
loop=hass.loop,
)
if not dependencies_tasks and not after_dependencies_tasks:
if not dependencies_tasks:
return []
if dependencies_tasks:
@@ -232,17 +239,9 @@ async def _async_process_dependencies(
integration.domain,
dependencies_tasks.keys(),
)
if after_dependencies_tasks:
_LOGGER.debug(
"Dependency %s will wait for after dependencies %s",
integration.domain,
after_dependencies_tasks.keys(),
)
async with hass.timeout.async_freeze(integration.domain):
results = await asyncio.gather(
*dependencies_tasks.values(), *after_dependencies_tasks.values()
)
results = await asyncio.gather(*dependencies_tasks.values())
failed = [
domain for idx, domain in enumerate(dependencies_tasks) if not results[idx]