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(variable_pool): handle invalid attributes in variable lookup (#9646)

-LAN-d5a93a6400bb
diff --git a/api/core/workflow/entities/variable_pool.py b/api/core/workflow/entities/variable_pool.py
index f8968990d48..3dc3395da1e 100644
--- a/api/core/workflow/entities/variable_pool.py
+++ b/api/core/workflow/entities/variable_pool.py
@@ -124,11 +124,15 @@ class VariablePool(BaseModel):
if value is None:
selector, attr = selector[:-1], selector[-1]
+ # Python support `attr in FileAttribute` after 3.12
+ if attr not in {item.value for item in FileAttribute}:
+ return None
value = self.get(selector)
- if isinstance(value, FileSegment):
- attr = FileAttribute(attr)
- attr_value = file_manager.get_attr(file=value.value, attr=attr)
- return variable_factory.build_segment(attr_value)
+ if not isinstance(value, FileSegment):
+ return None
+ attr = FileAttribute(attr)
+ attr_value = file_manager.get_attr(file=value.value, attr=attr)
+ return variable_factory.build_segment(attr_value)
return value
diff --git a/api/tests/unit_tests/core/workflow/test_variable_pool.py b/api/tests/unit_tests/core/workflow/test_variable_pool.py
index a1e4dda6271..9ea6acac171 100644
--- a/api/tests/unit_tests/core/workflow/test_variable_pool.py
+++ b/api/tests/unit_tests/core/workflow/test_variable_pool.py
@@ -33,8 +33,8 @@ def test_get_file_attribute(pool, file):
assert result.value == file.filename
# Test getting a non-existent attribute
- with pytest.raises(ValueError):
- pool.get(("node_1", "file_var", "non_existent_attr"))
+ result = pool.get(("node_1", "file_var", "non_existent_attr"))
+ assert result is None
def test_use_long_selector(pool):