Skip to content

Commit

Permalink
need to copy staged so it isn't mutated for with items
Browse files Browse the repository at this point in the history
  • Loading branch information
guzzijones committed Jul 12, 2023
1 parent 0f58986 commit d3541fb
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
5 changes: 2 additions & 3 deletions orquesta/conducting.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def deserialize(cls, data):
instance.contexts = data.get("contexts", list())
instance.routes = data.get("routes", list())
instance.sequence = data.get("sequence", list())
instance.staged = data.get("staged", list())
instance.staged = json_util.deepcopy(data.get("staged", list()))
instance.status = data.get("status", statuses.UNSET)
instance.tasks = data.get("tasks", dict())
instance.reruns = data.get("reruns", list())
Expand Down Expand Up @@ -481,8 +481,7 @@ def get_workflow_terminal_context(self):
for idx, task in other_term_tasks:
# Remove the initial context since the first task processed above already
# inclulded that and we only want to apply the differences.
in_ctx_idxs = [i for index, i in enumerate(task["ctxs"]["in"]) if
index != 0]
in_ctx_idxs = [i for index, i in enumerate(task["ctxs"]["in"]) if index != 0]

wf_term_ctx = dict_util.merge_dicts(
wf_term_ctx, self.get_task_context(in_ctx_idxs), overwrite=True
Expand Down
7 changes: 5 additions & 2 deletions orquesta/machines.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,11 @@ def add_context_to_task_item_event(cls, workflow_state, task_id, task_route, ac_
# Make a copy of the items and remove current item under evaluation.
staged_task = workflow_state.get_staged_task(task_id, task_route)
items = staged_task["items"]
items_status = [item.get("status", statuses.UNSET) for index, item in
enumerate(items) if index != ac_ex_event.item_id]
items_status = [
item.get("status", statuses.UNSET)
for index, item in enumerate(items)
if index != ac_ex_event.item_id
]

# Assess various situations.
# todo(aj) loop over list one time and add to each list
Expand Down
11 changes: 1 addition & 10 deletions orquesta/tests/unit/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,20 +209,11 @@ def assert_task_list(self, conductor, actual, expected):
expected_copy = copy.deepcopy(expected)

for task in actual_copy:
for staged_task in task["ctx"]["__state"]["staged"]:
if "items" in staged_task:
del staged_task["items"]

task["spec"] = task["spec"].serialize()

for task in expected_copy:
task["ctx"]["__current_task"] = {"id": task["id"], "route": task["route"]}
task["ctx"]["__state"] = copy.deepcopy(conductor.workflow_state.serialize())

for staged_task in task["ctx"]["__state"]["staged"]:
if "items" in staged_task:
del staged_task["items"]

task["ctx"]["__state"] = conductor.workflow_state.serialize()
task["spec"] = task["spec"].serialize()

self.assertListEqual(actual_copy, expected_copy)
Expand Down

0 comments on commit d3541fb

Please sign in to comment.