diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py index 172a4c53a..a5b2e0637 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_instances_controller.py @@ -377,19 +377,21 @@ def _process_instance_task_list( This is how we know what the state of each task is and how to color things. """ bpmn_process_ids = [] + bpmn_process = None if bpmn_process_guid: bpmn_process = BpmnProcessModel.query.filter_by(guid=bpmn_process_guid).first() - if bpmn_process is None: - raise ApiError( - error_code="bpmn_process_not_found", - message=( - f"Cannot find a bpmn process with guid '{bpmn_process_guid}' for process instance '{process_instance.id}'" - ), - status_code=400, - ) + else: + bpmn_process = process_instance.bpmn_process - bpmn_processes = TaskService.bpmn_process_and_descendants([bpmn_process]) - bpmn_process_ids = [p.id for p in bpmn_processes] + if bpmn_process is None: + raise ApiError( + error_code="bpmn_process_not_found", + message=(f"Cannot find a bpmn process with guid '{bpmn_process_guid}' for process instance '{process_instance.id}'"), + status_code=400, + ) + + bpmn_processes = TaskService.bpmn_process_and_descendants([bpmn_process]) + bpmn_process_ids = [p.id for p in bpmn_processes] task_model_query = db.session.query(TaskModel).filter( TaskModel.process_instance_id == process_instance.id, diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/task_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/task_service.py index 53fa993fc..3404015ae 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/task_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/task_service.py @@ -10,6 +10,7 @@ from SpiffWorkflow.bpmn.workflow import BpmnWorkflow # type: ignore from SpiffWorkflow.exceptions import WorkflowException # type: ignore from SpiffWorkflow.task import Task as SpiffTask # type: ignore from SpiffWorkflow.util.task import TaskState # type: ignore +from sqlalchemy import and_ from sqlalchemy import asc from spiffworkflow_backend.exceptions.error import TaskMismatchError @@ -565,6 +566,17 @@ class TaskService: direct_children = BpmnProcessModel.query.filter( BpmnProcessModel.direct_parent_process_id.in_(bpmn_process_ids) # type: ignore ).all() + direct_children = ( + BpmnProcessModel.query.join(TaskModel, TaskModel.guid == BpmnProcessModel.guid) + .join(TaskDefinitionModel, TaskDefinitionModel.id == TaskModel.task_definition_id) + .filter( + and_( + TaskDefinitionModel.typename == "SubWorkflowTask", + TaskModel.bpmn_process_id.in_(bpmn_process_ids), # type: ignore + ) + ) + .all() + ) if len(direct_children) > 0: return bpmn_processes + cls.bpmn_process_and_descendants(direct_children) return bpmn_processes