1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00

Prevent leak of current_entry context variable (#128145)

This commit is contained in:
epenet
2024-10-16 18:02:37 +02:00
committed by GitHub
parent 494511e099
commit 350a27575f
2 changed files with 81 additions and 1 deletions

View File

@@ -529,10 +529,21 @@ class ConfigEntry(Generic[_DataT]):
integration: loader.Integration | None = None,
) -> None:
"""Set up an entry."""
current_entry.set(self)
if self.source == SOURCE_IGNORE or self.disabled_by:
return
current_entry.set(self)
try:
await self.__async_setup_with_context(hass, integration)
finally:
current_entry.set(None)
async def __async_setup_with_context(
self,
hass: HomeAssistant,
integration: loader.Integration | None,
) -> None:
"""Set up an entry, with current_entry set."""
if integration is None and not (integration := self._integration_for_domain):
integration = await loader.async_get_integration(hass, self.domain)
self._integration_for_domain = integration