Abort reauth flows on config entry reload (#140931)

* Abort reauth flows on config entry reload

* Don't cancel reauth when reload is triggered by a reauth flow

* Revert "Don't cancel reauth when reload is triggered by a reauth flow"

This reverts commit f37c75621e.

* Don't fail in FlowManager._async_handle_step when the flow was aborted

* Update tplink config flow

* Add tests

* Don't allow create_entry from an aborted flow

* Add comment

* Adjust after merge with dev
This commit is contained in:
Erik Montnemery
2025-04-10 20:55:34 +02:00
committed by GitHub
parent 88428fc772
commit cf63175232
5 changed files with 62 additions and 21 deletions

View File

@@ -1521,10 +1521,9 @@ class ConfigEntriesFlowManager(
# Clean up issue if this is a reauth flow
if flow.context["source"] == SOURCE_REAUTH:
if (entry_id := flow.context.get("entry_id")) is not None and (
entry := self.config_entries.async_get_entry(entry_id)
) is not None:
issue_id = f"config_entry_reauth_{entry.domain}_{entry.entry_id}"
if (entry_id := flow.context.get("entry_id")) is not None:
# The config entry's domain is flow.handler
issue_id = f"config_entry_reauth_{flow.handler}_{entry_id}"
ir.async_delete_issue(self.hass, HOMEASSISTANT_DOMAIN, issue_id)
async def async_finish_flow(
@@ -2128,13 +2127,7 @@ class ConfigEntries:
# If the configuration entry is removed during reauth, it should
# abort any reauth flow that is active for the removed entry and
# linked issues.
for progress_flow in self.hass.config_entries.flow.async_progress_by_handler(
entry.domain, match_context={"entry_id": entry_id, "source": SOURCE_REAUTH}
):
if "flow_id" in progress_flow:
self.hass.config_entries.flow.async_abort(progress_flow["flow_id"])
issue_id = f"config_entry_reauth_{entry.domain}_{entry.entry_id}"
ir.async_delete_issue(self.hass, HOMEASSISTANT_DOMAIN, issue_id)
_abort_reauth_flows(self.hass, entry.domain, entry_id)
self._async_dispatch(ConfigEntryChange.REMOVED, entry)
@@ -2266,6 +2259,9 @@ class ConfigEntries:
# attempts.
entry.async_cancel_retry_setup()
# Abort any in-progress reauth flow and linked issues
_abort_reauth_flows(self.hass, entry.domain, entry_id)
if entry.domain not in self.hass.config.components:
# If the component is not loaded, just load it as
# the config entry will be loaded as well. We need
@@ -3786,3 +3782,13 @@ async def _async_get_flow_handler(
return handler
raise data_entry_flow.UnknownHandler
@callback
def _abort_reauth_flows(hass: HomeAssistant, domain: str, entry_id: str) -> None:
"""Abort reauth flows for an entry."""
for progress_flow in hass.config_entries.flow.async_progress_by_handler(
domain, match_context={"entry_id": entry_id, "source": SOURCE_REAUTH}
):
if "flow_id" in progress_flow:
hass.config_entries.flow.async_abort(progress_flow["flow_id"])