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: preserve empty list for FILE_LIST type in base_app_generator (#29618)

lif542eb04ad8b6
diff --git a/api/core/app/apps/base_app_generator.py b/api/core/app/apps/base_app_generator.py
index 02d58a07d17..a6aace168e3 100644
--- a/api/core/app/apps/base_app_generator.py
+++ b/api/core/app/apps/base_app_generator.py
@@ -105,8 +105,9 @@ class BaseAppGenerator:
variable_entity.type in {VariableEntityType.FILE, VariableEntityType.FILE_LIST}
and not variable_entity.required
):
- # Treat empty string (frontend default) or empty list as unset
- if not value and isinstance(value, (str, list)):
+ # Treat empty string (frontend default) as unset
+ # For FILE_LIST, allow empty list [] to pass through
+ if isinstance(value, str) and not value:
return None
if variable_entity.type in {
diff --git a/api/tests/unit_tests/core/app/apps/test_base_app_generator.py b/api/tests/unit_tests/core/app/apps/test_base_app_generator.py
index d622c3a555c..1000d713992 100644
--- a/api/tests/unit_tests/core/app/apps/test_base_app_generator.py
+++ b/api/tests/unit_tests/core/app/apps/test_base_app_generator.py
@@ -287,7 +287,7 @@ def test_validate_inputs_optional_file_with_empty_string():
def test_validate_inputs_optional_file_list_with_empty_list():
- """Test that optional FILE_LIST variable with empty list returns None"""
+ """Test that optional FILE_LIST variable with empty list returns empty list (not None)"""
base_app_generator = BaseAppGenerator()
var_file_list = VariableEntity(
@@ -302,6 +302,28 @@ def test_validate_inputs_optional_file_list_with_empty_list():
value=[],
)
+ # Empty list should be preserved, not converted to None
+ # This allows downstream components like document_extractor to handle empty lists properly
+ assert result == []
+
+
+def test_validate_inputs_optional_file_list_with_empty_string():
+ """Test that optional FILE_LIST variable with empty string returns None"""
+ base_app_generator = BaseAppGenerator()
+
+ var_file_list = VariableEntity(
+ variable="test_file_list",
+ label="test_file_list",
+ type=VariableEntityType.FILE_LIST,
+ required=False,
+ )
+
+ result = base_app_generator._validate_inputs(
+ variable_entity=var_file_list,
+ value="",
+ )
+
+ # Empty string should be treated as unset
assert result is None