Skip to content

Commit 2060047

Browse files
committed
feat: enhance workflow synchronization to accept remote tool folders and reject uploaded files
1 parent b6aacac commit 2060047

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

‎apps/knowledge/services/workflow_sync_source.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ def validate_workflow_sync_source(work_flow: dict, workflow_input: dict) -> None
99
source_node = next((node for node in (work_flow or {}).get("nodes", []) if node.get("id") == node_id), None)
1010
if source_node is None or source_node.get("properties", {}).get("kind") != "data-source":
1111
raise ValueError("The saved workflow data source no longer exists")
12-
if source_node.get("type") == "data-source-local-node" or data_source.get("file_list"):
12+
file_list = data_source.get("file_list") or []
13+
remote_tool_files = source_node.get("type") == "tool-lib-node" and all(
14+
isinstance(item, dict) and item.get("token") and not item.get("file_id") for item in file_list
15+
)
16+
if source_node.get("type") == "data-source-local-node" or (file_list and not remote_tool_files):
1317
raise ValueError("Local file data sources cannot be synchronized on a schedule")
1418
if source_node.get("type") == "data-source-web-node" and not str(data_source.get("source_url") or "").strip():
1519
raise ValueError("Web data source has no saved source URL")

‎apps/knowledge/tests.py‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,6 +1464,18 @@ def test_schedule_accepts_web_and_tool_sources_but_rejects_local_source(self):
14641464
{"data_source": {"node_id": "source"}},
14651465
)
14661466

1467+
def test_schedule_accepts_remote_tool_folder_but_rejects_uploaded_files(self):
1468+
tool_flow = {"nodes": [{"id": "source", "type": "tool-lib-node", "properties": {"kind": "data-source"}}]}
1469+
validate_workflow_sync_source(
1470+
tool_flow,
1471+
{"data_source": {"node_id": "source", "file_list": [{"type": "folder", "token": "folder-token"}]}},
1472+
)
1473+
with self.assertRaisesRegex(ValueError, "Local file"):
1474+
validate_workflow_sync_source(
1475+
tool_flow,
1476+
{"data_source": {"node_id": "source", "file_list": [{"file_id": "uploaded-file-id"}]}},
1477+
)
1478+
14671479
@patch("knowledge.task.sync.KnowledgeWorkflowActionSerializer")
14681480
@patch("knowledge.task.sync.KnowledgeSyncLog.objects.create")
14691481
@patch("knowledge.task.sync.QuerySet")
@@ -1592,12 +1604,18 @@ def test_scheduled_workflow_uses_saved_input_and_starts_an_action(self, query_se
15921604
delete_documents.assert_not_called()
15931605

15941606
knowledge.meta["sync_setting"]["sync_type"] = "incremental"
1595-
knowledge.meta["workflow_sync_input"]["data_source"] = {"node_id": "start-node", "query": "updated"}
1607+
knowledge.meta["workflow_sync_input"]["data_source"] = {
1608+
"node_id": "start-node",
1609+
"file_list": [{"type": "folder", "token": "folder-token"}],
1610+
}
15961611
workflow_query.filter.return_value.values_list.return_value.first.return_value = {
15971612
"nodes": [{"id": "start-node", "type": "tool-lib-node", "properties": {"kind": "data-source"}}]
15981613
}
15991614
self.assertTrue(scheduled_sync_workflow_knowledge.run(str(knowledge.id)))
1600-
self.assertEqual(action_serializer.return_value.action.call_args.args[0]["data_source"]["query"], "updated")
1615+
self.assertEqual(
1616+
action_serializer.return_value.action.call_args.args[0]["data_source"]["file_list"],
1617+
[{"type": "folder", "token": "folder-token"}],
1618+
)
16011619

16021620
@patch("knowledge.serializers.knowledge_workflow.WorkflowRunRegistry")
16031621
@patch("knowledge.serializers.knowledge_workflow.new_instance")

0 commit comments

Comments
 (0)