Skip to content

Commit

Permalink
Replace shallow parameter merge with deep merge function (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobsee authored Aug 17, 2020
1 parent 90b3e5e commit 0ae97a1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions resource-dispatcher/execution/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ def execute_step(fn, step, context):
if loop_over is None:
constructed_params = {}
if "params_from_context" in step:
constructed_params.update(context[step["params_from_context"]])
deep_merge(constructed_params, context[step["params_from_context"]])
if "params" in step:
constructed_params.update(step["params"])
deep_merge(constructed_params, step["params"])
return fn(context, constructed_params)
else:
if isinstance(context[loop_over], list):
Expand Down Expand Up @@ -101,6 +101,20 @@ def execute_step(fn, step, context):
raise Exception("Error: Tried to loop over a non-iterable context object.")


def deep_merge(merge_into, merge_from, path=None):
if path is None: path = []
for key in merge_from:
if key in merge_into:
if isinstance(merge_from[key], dict) and isinstance(merge_into[key], dict):
deep_merge(merge_into[key], merge_from[key], path + [str(key)])
elif merge_into[key] == merge_from[key]:
pass
else:
raise Exception('Cannot merge dictionary with non-dictionary element: %s' % '.'.join(path + [str(key)]))
else:
merge_into[key] = merge_from[key]


def handle_errors(task):

if "disable_error_handling" in task and task["disable_error_handling"]:
Expand Down

0 comments on commit 0ae97a1

Please sign in to comment.