Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(api): enhance data handling in RagPipelineDslService to filter credentials (#25926)

Mariesbb01c31f3026
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 22b3100d44d..a447f2848ad 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 88f28e03ef4..f74de1bcab5 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"] = [