Compare commits

...

1 Commits

Author SHA1 Message Date
G Johansson
1528e03ddc check async_forward_entry_setups needs to be awaited 2026-04-07 19:26:25 +00:00
2 changed files with 10 additions and 23 deletions

View File

@@ -1389,18 +1389,6 @@ class FlowCancelledError(Exception):
"""Error to indicate that a flow has been cancelled."""
def _report_non_awaited_platform_forwards(entry: ConfigEntry, what: str) -> None:
"""Report non awaited platform forwards."""
report_usage(
f"calls {what} for integration {entry.domain} with "
f"title: {entry.title} and entry_id: {entry.entry_id}, "
f"during setup without awaiting {what}, which can cause "
"the setup lock to be released before the setup is done",
core_behavior=ReportBehavior.LOG,
breaks_in_ha_version="2025.1",
)
class ConfigEntriesFlowManager(
data_entry_flow.FlowManager[ConfigFlowContext, ConfigFlowResult]
):
@@ -2680,10 +2668,6 @@ class ConfigEntries:
in each integration. This is to ensure that all platforms are loaded
before the entry is set up. This ensures that the config entry cannot
be unloaded before all platforms are loaded.
This method is more efficient than async_forward_entry_setup as
it can load multiple platforms at once and does not require a separate
import executor job for each platform.
"""
integration = await loader.async_get_integration(self.hass, entry.domain)
if not integration.platforms_are_loaded(platforms):
@@ -2705,8 +2689,11 @@ class ConfigEntries:
# If the lock was held when we stated, and it was released during
# the platform setup, it means they did not await the setup call.
if not entry.setup_lock.locked():
_report_non_awaited_platform_forwards(
entry, "async_forward_entry_setups"
raise HomeAssistantError(
f"Detected code that calls async_forward_entry_setups for integration "
f"{entry.domain} with title: {entry.title} and entry_id: {entry.entry_id}, "
f"during setup without awaiting async_forward_entry_setups, which can cause "
"the setup lock to be released before the setup is done",
)
async def _async_forward_entry_setups_locked(

View File

@@ -8044,15 +8044,15 @@ async def test_non_awaited_async_forward_entry_setups(
await hass.async_block_till_done()
forward_event.set()
await hass.async_block_till_done()
await task
assert (
message = (
"Detected code that calls async_forward_entry_setups for integration "
"test with title: Mock Title and entry_id: test2, during setup without "
"awaiting async_forward_entry_setups, which can cause the setup lock "
"to be released before the setup is done. This will stop working in "
"Home Assistant 2025.1, please report this issue"
) in caplog.text
"to be released before the setup is done"
)
with pytest.raises(HomeAssistantError, match=message):
await task
async def test_config_entry_unloaded_during_platform_setup(