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: fix allow handle value is none (#33031)

wangxiaoleid2208ad43e3d
diff --git a/api/dify_graph/nodes/document_extractor/node.py b/api/dify_graph/nodes/document_extractor/node.py
index e1ae6f01991..c26b18aac9d 100644
--- a/api/dify_graph/nodes/document_extractor/node.py
+++ b/api/dify_graph/nodes/document_extractor/node.py
@@ -83,8 +83,18 @@ class DocumentExtractorNode(Node[DocumentExtractorNodeData]):
value = variable.value
inputs = {"variable_selector": variable_selector}
+ if isinstance(value, list):
+ value = list(filter(lambda x: x, value))
process_data = {"documents": value if isinstance(value, list) else [value]}
+ if not value:
+ return NodeRunResult(
+ status=WorkflowNodeExecutionStatus.SUCCEEDED,
+ inputs=inputs,
+ process_data=process_data,
+ outputs={"text": ArrayStringSegment(value=[])},
+ )
+
try:
if isinstance(value, list):
extracted_text_list = [
@@ -112,6 +122,7 @@ class DocumentExtractorNode(Node[DocumentExtractorNodeData]):
else:
raise DocumentExtractorError(f"Unsupported variable type: {type(value)}")
except DocumentExtractorError as e:
+ logger.warning(e, exc_info=True)
return NodeRunResult(
status=WorkflowNodeExecutionStatus.FAILED,
error=str(e),
diff --git a/api/tests/unit_tests/core/workflow/nodes/test_document_extractor_node.py b/api/tests/unit_tests/core/workflow/nodes/test_document_extractor_node.py
index abdf0954c4c..13275d4be63 100644
--- a/api/tests/unit_tests/core/workflow/nodes/test_document_extractor_node.py
+++ b/api/tests/unit_tests/core/workflow/nodes/test_document_extractor_node.py
@@ -87,6 +87,38 @@ def test_run_invalid_variable_type(document_extractor_node, mock_graph_runtime_s
assert "is not an ArrayFileSegment" in result.error
+def test_run_empty_file_list_returns_succeeded(document_extractor_node, mock_graph_runtime_state):
+ """Empty file list should return SUCCEEDED with empty documents and ArrayStringSegment([])."""
+ document_extractor_node.graph_runtime_state = mock_graph_runtime_state
+
+ # Provide an actual ArrayFileSegment with an empty list
+ mock_graph_runtime_state.variable_pool.get.return_value = ArrayFileSegment(value=[])
+
+ result = document_extractor_node._run()
+
+ assert isinstance(result, NodeRunResult)
+ assert result.status == WorkflowNodeExecutionStatus.SUCCEEDED, result.error
+ assert result.process_data.get("documents") == []
+ assert result.outputs["text"] == ArrayStringSegment(value=[])
+
+
+def test_run_none_only_file_list_returns_succeeded(document_extractor_node, mock_graph_runtime_state):
+ """A file list containing only None (e.g., [None]) should be filtered to [] and succeed."""
+ document_extractor_node.graph_runtime_state = mock_graph_runtime_state
+
+ # Use a Mock to bypass type validation for None entries in the list
+ afs = Mock(spec=ArrayFileSegment)
+ afs.value = [None]
+ mock_graph_runtime_state.variable_pool.get.return_value = afs
+
+ result = document_extractor_node._run()
+
+ assert isinstance(result, NodeRunResult)
+ assert result.status == WorkflowNodeExecutionStatus.SUCCEEDED, result.error
+ assert result.process_data.get("documents") == []
+ assert result.outputs["text"] == ArrayStringSegment(value=[])
+
+
@pytest.mark.parametrize(
("mime_type", "file_content", "expected_text", "transfer_method", "extension"),
[