From 65a1da98fa7d4076350186c7b5df35c5e26d130c Mon Sep 17 00:00:00 2001
From: Taylor Salo <tsalo006@fiu.edu>
Date: Mon, 16 Oct 2023 16:44:16 -0400
Subject: [PATCH] Maybe fix bug?

---
 xcp_d/tests/test_utils_utils.py | 6 ++++++
 xcp_d/utils/utils.py            | 4 ++--
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/xcp_d/tests/test_utils_utils.py b/xcp_d/tests/test_utils_utils.py
index 19ddb197a..5f5882714 100644
--- a/xcp_d/tests/test_utils_utils.py
+++ b/xcp_d/tests/test_utils_utils.py
@@ -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"]
 
diff --git a/xcp_d/utils/utils.py b/xcp_d/utils/utils.py
index f40ffdaf5..6a7e16185 100644
--- a/xcp_d/utils/utils.py
+++ b/xcp_d/utils/utils.py
@@ -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