From 5856bbc07b4cbd1f7a3fb5f588fca9b0fb1a5769 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Mon, 1 Apr 2024 15:37:30 -1000 Subject: [PATCH] Add missing platforms_exist guard to check_config (#114600) * Add missing platforms_exist guard to check_config related issue #112811 When the exception hits, the config will end up being saved in the traceback so the memory is never released. This matches the check_config code to homeassistant.config to avoid having the exception thrown. * patch * merge branch --- homeassistant/helpers/check_config.py | 19 ++++++++++--------- tests/helpers/test_check_config.py | 2 ++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/homeassistant/helpers/check_config.py b/homeassistant/helpers/check_config.py index 8537f442595..78dddb12381 100644 --- a/homeassistant/helpers/check_config.py +++ b/homeassistant/helpers/check_config.py @@ -198,15 +198,16 @@ async def async_check_ha_config_file( # noqa: C901 # Check if the integration has a custom config validator config_validator = None - try: - config_validator = await integration.async_get_platform("config") - except ImportError as err: - # Filter out import error of the config platform. - # If the config platform contains bad imports, make sure - # that still fails. - if err.name != f"{integration.pkg_path}.config": - result.add_error(f"Error importing config platform {domain}: {err}") - continue + if integration.platforms_exists(("config",)): + try: + config_validator = await integration.async_get_platform("config") + except ImportError as err: + # Filter out import error of the config platform. + # If the config platform contains bad imports, make sure + # that still fails. + if err.name != f"{integration.pkg_path}.config": + result.add_error(f"Error importing config platform {domain}: {err}") + continue if config_validator is not None and hasattr( config_validator, "async_validate_config" diff --git a/tests/helpers/test_check_config.py b/tests/helpers/test_check_config.py index fd94c453e51..de7edf42dc2 100644 --- a/tests/helpers/test_check_config.py +++ b/tests/helpers/test_check_config.py @@ -350,6 +350,7 @@ async def test_config_platform_import_error(hass: HomeAssistant) -> None: side_effect=ImportError("blablabla"), ), patch("os.path.isfile", return_value=True), + patch("homeassistant.loader.Integration.platforms_exists", return_value=True), patch_yaml_files(files), ): res = await async_check_ha_config_file(hass) @@ -373,6 +374,7 @@ async def test_platform_import_error(hass: HomeAssistant) -> None: "homeassistant.loader.Integration.async_get_platform", side_effect=[None, ImportError("blablabla")], ), + patch("homeassistant.loader.Integration.platforms_exists", return_value=True), patch("os.path.isfile", return_value=True), patch_yaml_files(files), ):