mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-07-25 04:44:27 +08:00
fix(variable_pool): handle invalid attributes in variable lookup (#9646)
This commit is contained in:
parent
01a2513812
commit
d5a93a6400
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user