From d2e341367eca89ac55b1a374babe103cece815d4 Mon Sep 17 00:00:00 2001 From: QuantumGhost Date: Wed, 3 Sep 2025 12:30:20 +0800 Subject: [PATCH] fix(api): fix relations of WorkflowNodeExecutionModel not preloaded `WorkflowNodeExecutionModel.offload_data` should be preloaded to provide info about the offloading information of execution record. The `RagPipelineService.get_node_last_run` does not utilize `DifyAPISQLAlchemyWorkflowNodeExecutionRepository` so the loading logics is not changed. In the commit we migrate to calling `DifyAPISQLAlchemyWorkflowNodeExecutionRepository` to avoid such issue. --- api/services/rag_pipeline/rag_pipeline.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/api/services/rag_pipeline/rag_pipeline.py b/api/services/rag_pipeline/rag_pipeline.py index d0793bf7cf..848d0d6ea7 100644 --- a/api/services/rag_pipeline/rag_pipeline.py +++ b/api/services/rag_pipeline/rag_pipeline.py @@ -1162,18 +1162,15 @@ class RagPipelineService: def get_node_last_run( self, pipeline: Pipeline, workflow: Workflow, node_id: str ) -> WorkflowNodeExecutionModel | None: - # TODO(QuantumGhost): This query is not fully covered by index. - criteria = ( - WorkflowNodeExecutionModel.tenant_id == pipeline.tenant_id, - WorkflowNodeExecutionModel.app_id == pipeline.id, - WorkflowNodeExecutionModel.workflow_id == workflow.id, - WorkflowNodeExecutionModel.node_id == node_id, + node_execution_service_repo = DifyAPIRepositoryFactory.create_api_workflow_node_execution_repository( + sessionmaker(db.engine) ) - node_exec = ( - db.session.query(WorkflowNodeExecutionModel) - .filter(*criteria) - .order_by(WorkflowNodeExecutionModel.created_at.desc()) - .first() + + node_exec = node_execution_service_repo.get_node_last_execution( + tenant_id=pipeline.tenant_id, + app_id=pipeline.id, + workflow_id=workflow.id, + node_id=node_id, ) return node_exec