From f2343e11cf503b739c471825bb0e3260e612dcf7 Mon Sep 17 00:00:00 2001 From: Elizabeth Esswein Date: Thu, 20 Jun 2024 10:23:05 -0400 Subject: [PATCH] omit default on inclusive gw with matched conditions --- .../bpmn/specs/mixins/inclusive_gateway.py | 6 +++--- SpiffWorkflow/specs/MultiChoice.py | 13 ++++++++----- tests/SpiffWorkflow/bpmn/InclusiveGatewayTest.py | 5 +++++ 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/SpiffWorkflow/bpmn/specs/mixins/inclusive_gateway.py b/SpiffWorkflow/bpmn/specs/mixins/inclusive_gateway.py index ca5b5d72..e840d26e 100644 --- a/SpiffWorkflow/bpmn/specs/mixins/inclusive_gateway.py +++ b/SpiffWorkflow/bpmn/specs/mixins/inclusive_gateway.py @@ -119,8 +119,8 @@ def check(spec): return complete def _run_hook(self, my_task): - outputs = self._get_matching_outputs(my_task) - if len(outputs) == 0: + matches, defaults = self._get_matching_outputs(my_task) + if len(matches + 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 diff --git a/SpiffWorkflow/specs/MultiChoice.py b/SpiffWorkflow/specs/MultiChoice.py index 3bf5b946..dd5d9da4 100644 --- a/SpiffWorkflow/specs/MultiChoice.py +++ b/SpiffWorkflow/specs/MultiChoice.py @@ -103,17 +103,20 @@ def _predict_hook(self, my_task): my_task._add_child(spec, TaskState.MAYBE) def _get_matching_outputs(self, my_task): - outputs = [] + matches, defaults = [], [] for condition, output in self.cond_task_specs: if self.choice is not None and output not in self.choice: continue - if condition is None or condition._matches(my_task): - outputs.append(my_task.workflow.spec.get_task_spec_from_name(output)) - return outputs + if condition is None: + defaults.append(my_task.workflow.spec.get_task_spec_from_name(output)) + elif condition._matches(my_task): + matches.append(my_task.workflow.spec.get_task_spec_from_name(output)) + return matches, 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) + matches, defaults = self._get_matching_outputs(my_task) + my_task._sync_children(matches + defaults, TaskState.FUTURE) for child in my_task.children: child.task_spec._predict(child, mask=TaskState.FUTURE|TaskState.PREDICTED_MASK) return True diff --git a/tests/SpiffWorkflow/bpmn/InclusiveGatewayTest.py b/tests/SpiffWorkflow/bpmn/InclusiveGatewayTest.py index d592e15e..b22de8bc 100644 --- a/tests/SpiffWorkflow/bpmn/InclusiveGatewayTest.py +++ b/tests/SpiffWorkflow/bpmn/InclusiveGatewayTest.py @@ -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})