Skip to content

Commit

Permalink
Yaml merge bugfix: removed concurrent iteration and modification (#264)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcparaf authored Aug 8, 2024
1 parent aef57a0 commit 5c33a06
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion iac_validate/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def merge_dict(
merge_dict(value, node, merge_list_items)
elif isinstance(value, list):
if key not in destination:
destination[key] = value
destination[key] = []
if isinstance(destination[key], list):
for i in value:
merge_list_item(i, destination[key], merge_list_items)
Expand Down
14 changes: 14 additions & 0 deletions tests/unit/test_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,20 @@ def test_merge_dict():
result = {"root": {"child1": "abc", "child2": "def"}}
yaml.merge_dict(source, destination)
assert destination == result
# make sure that the code doesn't hang when merging lists of lists
source = {
"switch_link_aggregations": [
{
"switch_ports": [
{"port_id": "7", "serial": "asd"},
{"port_id": "8", "serial": "qwe"},
]
}
]
}
destination = {}
yaml.merge_dict(source, destination)
assert destination == source


def test_merge_list_item():
Expand Down

0 comments on commit 5c33a06

Please sign in to comment.