diff --git a/app/api/endpoints/workflow_execution.py b/app/api/endpoints/workflow_execution.py index a1f2d00d42e6eb7aefbd17b81844cd95b721f884..b9da62b5fc78f5f6bf0e7c77b91f2dddc3e29f3a 100644 --- a/app/api/endpoints/workflow_execution.py +++ b/app/api/endpoints/workflow_execution.py @@ -131,7 +131,7 @@ async def start_workflow( slurm_client=slurm_client, ) - return execution + return WorkflowExecutionOut.from_db_model(execution, workflow_id=workflow_version.workflow_id) @router.post( @@ -229,7 +229,7 @@ async def start_arbitrary_workflow( slurm_client=slurm_client, ) - return execution + return WorkflowExecutionOut.from_db_model(execution) @router.get("", status_code=status.HTTP_200_OK, summary="Get all workflow executions") @@ -283,7 +283,12 @@ async def list_workflow_executions( executions = await CRUDWorkflowExecution.list( db, uid=user_id, workflow_version_id=workflow_version_id, status_list=execution_status ) - return executions + return [ + WorkflowExecutionOut.from_db_model( + execution, execution.workflow_version.workflow_id if execution.workflow_version is not None else None + ) + for execution in executions + ] @router.get("/{eid}", status_code=status.HTTP_200_OK, summary="Get a workflow execution") @@ -313,7 +318,10 @@ async def get_workflow_execution( """ rbac_operation = "read" if workflow_execution.user_id == current_user.uid else "read_any" await authorization(rbac_operation) - return workflow_execution + return WorkflowExecutionOut.from_db_model( + workflow_execution, + workflow_execution.workflow_version.workflow_id if workflow_execution.workflow_version is not None else None, + ) @router.delete("/{eid}", status_code=status.HTTP_204_NO_CONTENT, summary="Delete a workflow execution") diff --git a/app/crud/crud_workflow_execution.py b/app/crud/crud_workflow_execution.py index ff55177415cca94a67e0bd3c1fb549478c24eaf7..382c87cc7dc35a0e8dfdbc1fe9e21a2af01d7254 100644 --- a/app/crud/crud_workflow_execution.py +++ b/app/crud/crud_workflow_execution.py @@ -3,6 +3,7 @@ from uuid import UUID from clowmdb.models import WorkflowExecution from sqlalchemy import delete, or_, select, update from sqlalchemy.ext.asyncio import AsyncSession +from sqlalchemy.orm import joinedload from app.schemas.workflow_execution import DevWorkflowExecutionIn, WorkflowExecutionIn @@ -68,7 +69,11 @@ class CRUDWorkflowExecution: The workflow execution with the given id if it exists, None otherwise """ eid = execution_id.bytes if isinstance(execution_id, UUID) else execution_id - stmt = select(WorkflowExecution).where(WorkflowExecution._execution_id == eid) + stmt = ( + select(WorkflowExecution) + .where(WorkflowExecution._execution_id == eid) + .options(joinedload(WorkflowExecution.workflow_version)) + ) execution = (await db.execute(stmt)).scalar() return execution @@ -95,10 +100,10 @@ class CRUDWorkflowExecution: Returns ------- - workflow_executions : list[clowmdb.models.WorkflowExecution.WorkflowExecutionStatus] + workflow_executions : list[clowmdb.models.WorkflowExecution] List of all workflow executions with applied filters. """ - stmt = select(WorkflowExecution) + stmt = select(WorkflowExecution).options(joinedload(WorkflowExecution.workflow_version)) if uid is not None: stmt = stmt.where(WorkflowExecution.user_id == uid) if workflow_version_id is not None: diff --git a/app/schemas/workflow_execution.py b/app/schemas/workflow_execution.py index 3c9ba61a73434ec39e8f468e1d3be04b91bcd512..7c116def59a28eb75ccc904696bdb205f40e3110 100644 --- a/app/schemas/workflow_execution.py +++ b/app/schemas/workflow_execution.py @@ -55,9 +55,21 @@ class WorkflowExecutionOut(_BaseWorkflowExecution): workflow_version_id: str | None = Field( # type: ignore[assignment] ..., description="Workflow version git commit hash", example="ba8bcd9294c2c96aedefa1763a84a18077c50c0f" ) + workflow_id: UUID | None = Field( + ..., description="Id of the workflow", example="0cc78936-381b-4bdd-999d-736c40591078" + ) - class Config: - orm_mode = True + @staticmethod + def from_db_model(workflow_execution: WorkflowExecution, workflow_id: UUID | None = None) -> "WorkflowExecutionOut": + return WorkflowExecutionOut( + execution_id=workflow_execution.execution_id, + user_id=workflow_execution.user_id, + start_time=workflow_execution.start_time, + end_time=workflow_execution.end_time, + status=workflow_execution.status, + workflow_version_id=workflow_execution.workflow_version_id, + workflow_id=workflow_id, + ) class DevWorkflowExecutionIn(BaseModel):