fix: avoid checking variables with empty value (#5367)

fix: enhance load_from_db field checks in custom component update and parameter loading

- Updated the condition in  to ensure that  only includes fields with a defined value.
- Modified the  function to skip parameters that are either not present or have a falsy value, improving robustness in parameter handling.
This commit is contained in:
Gabriel Luiz Freitas Almeida 2024-12-19 14:01:15 -03:00 committed by GitHub
commit b7f5a7fe9b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 2 deletions

View file

@ -622,7 +622,7 @@ async def custom_component_update(
load_from_db_fields = [
field_name
for field_name, field_dict in template.items()
if isinstance(field_dict, dict) and field_dict.get("load_from_db")
if isinstance(field_dict, dict) and field_dict.get("load_from_db") and field_dict.get("value")
]
params = await update_params_with_load_from_db_fields(cc_instance, params, load_from_db_fields)
cc_instance.set_attributes(params)

View file

@ -111,7 +111,7 @@ async def update_params_with_load_from_db_fields(
fallback_to_env_vars=False,
):
for field in load_from_db_fields:
if field not in params:
if field not in params or not params[field]:
continue
try: