Skip to content

Commit

Permalink
omit default on inclusive gw with matched conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
essweine committed Jun 20, 2024
1 parent 7da6dd9 commit d9fca82
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions SpiffWorkflow/bpmn/specs/mixins/inclusive_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ def check(spec):

def _run_hook(self, my_task):
outputs = self._get_matching_outputs(my_task)
if len(outputs) == 0:
defaults = self._get_default_outputs(my_task)
matches = [ts for ts in outputs if ts not in defaults]
if len(outputs) == 0 and len(defaults) == 0:
raise WorkflowTaskException('No conditions satisfied on gateway', task=my_task)
my_task._sync_children(outputs, TaskState.FUTURE)
my_task._sync_children(matches or defaults, TaskState.FUTURE)
return True
4 changes: 4 additions & 0 deletions SpiffWorkflow/specs/MultiChoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def _get_matching_outputs(self, my_task):
outputs.append(my_task.workflow.spec.get_task_spec_from_name(output))
return outputs

def _get_default_outputs(self, my_task):
defaults = [output for cond, output in self.cond_task_specs if cond is None]
return [my_task.workflow.spec.get_task_spec_from_name(output) for output in defaults]

def _run_hook(self, my_task):
"""Runs the task. Should not be called directly."""
my_task._sync_children(self._get_matching_outputs(my_task), TaskState.FUTURE)
Expand Down
5 changes: 5 additions & 0 deletions tests/SpiffWorkflow/bpmn/InclusiveGatewayTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ def testNoPathFromSecondGateway(self):

def testParallelCondition(self):
self.set_data({'v': 0, 'u': 1, 'w': 1})
gw = self.workflow.get_next_task(state=TaskState.READY)
gw.run()
self.assertIsNone(self.workflow.get_next_task(spec_name='increment_v'))
self.assertTrue(self.workflow.get_next_task(spec_name='u_plus_v').state, TaskState.READY)
self.assertTrue(self.workflow.get_next_task(spec_name='w_plus_v').state, TaskState.READY)
self.workflow.do_engine_steps()
self.assertTrue(self.workflow.is_completed())
self.assertDictEqual(self.workflow.data, {'v': 0, 'u': 1, 'w': 1})
Expand Down

0 comments on commit d9fca82

Please sign in to comment.