Skip to content

Commit 96b581a

Browse files
authored
Merge pull request #405 from sartography/bugfix/reset-inside-subworkflow-with-boundary-event
fix bug in reset inside subprocess with boundary event
2 parents 10c54a4 + 89511ef commit 96b581a

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

SpiffWorkflow/bpmn/workflow.py

+15-16
Original file line numberDiff line numberDiff line change
@@ -217,29 +217,28 @@ def get_task_from_id(self, task_id):
217217
def reset_from_task_id(self, task_id, data=None, remove_subprocess=True):
218218

219219
task = self.get_task_from_id(task_id)
220-
run_task_at_end = False
221-
if isinstance(task.parent.task_spec, BoundaryEventSplit):
222-
task = task.parent
223-
run_task_at_end = True # we jumped up one level, so exectute so we are on the correct task as requested.
224-
225-
descendants = []
226220
# Since recursive deletion of subprocesses requires access to the tasks, we have to delete any subprocesses first
227221
# We also need diffeent behavior for the case where we explictly reset to a subprocess (in which case we delete it)
228222
# vs resetting inside (where we leave it and reset the tasks that descend from it)
229-
for item in task:
230-
if item == task and not remove_subprocess:
231-
continue
232-
if item.id in self.subprocesses:
233-
descendants.extend(self.delete_subprocess(item))
234-
descendants.extend(super().reset_from_task_id(task.id, data))
223+
descendants = []
224+
225+
# If we're resetting to a boundary event, we also have to delete subprocesses underneath the attached events
226+
top = task if not isinstance(task.parent.task_spec, BoundaryEventSplit) else task.parent
227+
for desc in filter(lambda t: t.id in self.subprocesses, top):
228+
if desc != task or remove_subprocess:
229+
descendants.extend(self.delete_subprocess(desc))
230+
231+
# This resets the boundary event branches
232+
if isinstance(task.parent.task_spec, BoundaryEventSplit):
233+
for child in task.parent.children:
234+
descendants.extend(super().reset_from_task_id(child.id, data if child == task else None))
235+
else:
236+
descendants.extend(super().reset_from_task_id(task.id, data))
235237

236238
if task.workflow.parent_task_id is not None:
237239
sp_task = self.get_task_from_id(task.workflow.parent_task_id)
238240
descendants.extend(self.reset_from_task_id(sp_task.id, remove_subprocess=False))
239-
sp_task._set_state(TaskState.WAITING)
240-
241-
if run_task_at_end:
242-
task.run()
241+
sp_task._set_state(TaskState.STARTED)
243242

244243
return descendants
245244

tests/SpiffWorkflow/bpmn/NestedProcessesTest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def testResetToIntermediate(self):
4949
sub = [t for t in self.workflow.get_tasks() if t.task_spec.bpmn_name == 'Nested level 1'][0]
5050
self.workflow.reset_from_task_id(task.id)
5151
self.assertEqual(task.state, TaskState.READY)
52-
self.assertEqual(sub.state, TaskState.WAITING)
52+
self.assertEqual(sub.state, TaskState.STARTED)
5353
self.assertEqual(len(self.workflow.subprocesses), 1)
5454
task.run()
5555

tests/SpiffWorkflow/bpmn/ResetTokenOnBoundaryEventTest.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def reset_to_subprocess(self, save_restore=False):
6767

6868
# The task we returned to should be ready, the subprocess should be waiting, the final task should be future
6969
sub = self.workflow.get_next_task(spec_name='subprocess')
70-
self.assertEqual(sub.state, TaskState.WAITING)
70+
self.assertEqual(sub.state, TaskState.STARTED)
7171
self.assertEqual(task.state, TaskState.READY)
7272
final = self.workflow.get_next_task(spec_name='Final')
7373
self.assertEqual(final.state, TaskState.FUTURE)

0 commit comments

Comments
 (0)