Skip to content

Commit

Permalink
Fixed rupdate bug merging list into value
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel Collins committed Apr 8, 2020
1 parent 0cf9a9d commit 7b8c5b8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions labthings/core/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,15 @@ def rupdate(destination_dict, update_dict):
for k, v in update_dict.items():
# Merge lists if they're present in both objects
if isinstance(v, list):
# If key is missing from destination, create the list
if k not in destination_dict:
destination_dict[k] = []
# If destination value is also a list, merge
if isinstance(destination_dict[k], list):
destination_dict[k].extend(v)
# If destination exists but isn't a list, replace
else:
destination_dict[k] = v
# Recursively merge dictionaries if the element is a dictionary
elif isinstance(v, collections.abc.Mapping):
if k not in destination_dict:
Expand Down

0 comments on commit 7b8c5b8

Please sign in to comment.