diff --git a/app/utils.py b/app/utils.py index 75f301b72..554ccc83c 100644 --- a/app/utils.py +++ b/app/utils.py @@ -651,9 +651,9 @@ def merge_jsonlike(source, destination): return True def merge_lists(source, destination): - last_dest_idx = len(destination) - 1 + last_src_idx = len(source) - 1 for idx, item in enumerate(destination): - if idx <= last_dest_idx: + if idx <= last_src_idx: # assign destination value if can't be merged into source if merge_items(source[idx], destination[idx]) is False: source[idx] = destination[idx] diff --git a/tests/app/test_utils.py b/tests/app/test_utils.py index b198cf1b0..1f5cd0c8e 100644 --- a/tests/app/test_utils.py +++ b/tests/app/test_utils.py @@ -630,6 +630,8 @@ def test_get_sample_template_returns_template(template_type): ([{"b": "c"}], [{"b": "e"}], [{"b": "e"}]), # if nested dicts in lists have different keys, additive behaviour ([{"b": "c"}], [{"d": {"e": "f"}}], [{"b": "c", "d": {"e": "f"}}]), + # if dicts in destination list but not source, they just get added to end of source + ([{"a": "b"}], [{"a": "b"}, {"a": "b"}, {"c": "d"}], [{"a": "b"}, {"a": "b"}, {"c": "d"}]), # merge a dict with a null object returns that dict (does not work the other way round) ({"a": {"b": "c"}}, None, {"a": {"b": "c"}}), # double nested dicts, new adds new Boolean key: value, additive behaviour