From bb01c31f30262d88c3f1cac251fbad780e558309 Mon Sep 17 00:00:00 2001 From: Maries Date: Thu, 18 Sep 2025 18:36:49 +0800 Subject: [PATCH] fix(api): enhance data handling in RagPipelineDslService to filter credentials (#25926) --- .../datasets/rag_pipeline/rag_pipeline_import.py | 6 ++++-- .../rag_pipeline/rag_pipeline_dsl_service.py | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/api/controllers/console/datasets/rag_pipeline/rag_pipeline_import.py b/api/controllers/console/datasets/rag_pipeline/rag_pipeline_import.py index 22b3100d44..a447f2848a 100644 --- a/api/controllers/console/datasets/rag_pipeline/rag_pipeline_import.py +++ b/api/controllers/console/datasets/rag_pipeline/rag_pipeline_import.py @@ -118,12 +118,14 @@ class RagPipelineExportApi(Resource): # Add include_secret params parser = reqparse.RequestParser() - parser.add_argument("include_secret", type=bool, default=False, location="args") + parser.add_argument("include_secret", type=str, default="false", location="args") args = parser.parse_args() with Session(db.engine) as session: export_service = RagPipelineDslService(session) - result = export_service.export_rag_pipeline_dsl(pipeline=pipeline, include_secret=args["include_secret"]) + result = export_service.export_rag_pipeline_dsl( + pipeline=pipeline, include_secret=args["include_secret"] == "true" + ) return {"data": result}, 200 diff --git a/api/services/rag_pipeline/rag_pipeline_dsl_service.py b/api/services/rag_pipeline/rag_pipeline_dsl_service.py index 88f28e03ef..f74de1bcab 100644 --- a/api/services/rag_pipeline/rag_pipeline_dsl_service.py +++ b/api/services/rag_pipeline/rag_pipeline_dsl_service.py @@ -685,12 +685,24 @@ class RagPipelineDslService: workflow_dict = workflow.to_dict(include_secret=include_secret) for node in workflow_dict.get("graph", {}).get("nodes", []): - if node.get("data", {}).get("type", "") == NodeType.KNOWLEDGE_RETRIEVAL.value: - dataset_ids = node["data"].get("dataset_ids", []) + node_data = node.get("data", {}) + if not node_data: + continue + data_type = node_data.get("type", "") + if data_type == NodeType.KNOWLEDGE_RETRIEVAL.value: + dataset_ids = node_data.get("dataset_ids", []) node["data"]["dataset_ids"] = [ self.encrypt_dataset_id(dataset_id=dataset_id, tenant_id=pipeline.tenant_id) for dataset_id in dataset_ids ] + # filter credential id from tool node + if not include_secret and data_type == NodeType.TOOL.value: + node_data.pop("credential_id", None) + # filter credential id from agent node + if not include_secret and data_type == NodeType.AGENT.value: + for tool in node_data.get("agent_parameters", {}).get("tools", {}).get("value", []): + tool.pop("credential_id", None) + export_data["workflow"] = workflow_dict dependencies = self._extract_dependencies_from_workflow(workflow) export_data["dependencies"] = [