Skip to content

Commit

Permalink
Maybe fix bug?
Browse files Browse the repository at this point in the history
  • Loading branch information
tsalo committed Oct 16, 2023
1 parent 2b169d6 commit 65a1da9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions xcp_d/tests/test_utils_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,12 @@ def test_make_dictionary():
assert metadata["Sources"] == "a"
assert out_metadata["Sources"] == ["a", "b"]

metadata = {"Sources": ["a"]}
out_metadata = utils._make_dictionary(metadata, Sources="b")
# Ensure the original dictionary isn't modified.
assert metadata["Sources"] == ["a"]
assert out_metadata["Sources"] == ["a", "b"]

out_metadata = utils._make_dictionary(metadata=None, Sources=["b"])
assert out_metadata["Sources"] == ["b"]

Expand Down
4 changes: 2 additions & 2 deletions xcp_d/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,9 @@ def _make_dictionary(metadata=None, **kwargs):
for key, value in kwargs.items():
if key not in metadata.keys():
out_metadata[key] = value
elif isinstance(value, list):
elif isinstance(value, list) or isinstance(out_metadata[key], list):
# Append the values if they're a list
out_metadata[key] = _listify(out_metadata[key]) + value
out_metadata[key] = _listify(out_metadata[key]) + _listify(value)
else:
# Overwrite the old value
out_metadata[key] = value

Check warning on line 562 in xcp_d/utils/utils.py

View check run for this annotation

Codecov / codecov/patch

xcp_d/utils/utils.py#L562

Added line #L562 was not covered by tests
Expand Down

0 comments on commit 65a1da9

Please sign in to comment.