Skip to content

Commit

Permalink
Fix empty files included by !include_dir_named (#108489)
Browse files Browse the repository at this point in the history
Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
  • Loading branch information
2 people authored and frenck committed Jan 20, 2024
1 parent fb700cc commit ea8fc64
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion homeassistant/util/yaml/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,12 @@ def _include_dir_named_yaml(loader: LoaderType, node: yaml.nodes.Node) -> NodeDi
filename = os.path.splitext(os.path.basename(fname))[0]
if os.path.basename(fname) == SECRET_YAML:
continue
mapping[filename] = load_yaml(fname, loader.secrets)
loaded_yaml = load_yaml(fname, loader.secrets)
if loaded_yaml is None:
# Special case, an empty file included by !include_dir_named is treated
# as an empty dictionary
loaded_yaml = NodeDictClass()
mapping[filename] = loaded_yaml
return _add_reference(mapping, loader, node)


Expand Down
2 changes: 1 addition & 1 deletion tests/util/yaml/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def test_include_dir_list_recursive(
),
(
{"/test/first.yaml": "1", "/test/second.yaml": None},
{"first": 1, "second": None},
{"first": 1, "second": {}},
),
],
)
Expand Down

0 comments on commit ea8fc64

Please sign in to comment.