Skip to content

Commit 3079a35

Browse files
committed
fix: issue langgenius#10596 by cast ArrayObjectVariable to ArrayFileSegment when node are files outputs
Signed-off-by: yihong0618 <[email protected]>
1 parent 284bb7a commit 3079a35

File tree

1 file changed

+13
-3
lines changed
  • api/core/workflow/nodes/list_operator

1 file changed

+13
-3
lines changed

api/core/workflow/nodes/list_operator/node.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from collections.abc import Callable, Sequence
22
from typing import Literal, Union
33

4-
from core.file import File
5-
from core.variables import ArrayFileSegment, ArrayNumberSegment, ArrayStringSegment
4+
from core.file import FILE_MODEL_IDENTITY, File
5+
from core.variables import ArrayFileSegment, ArrayNumberSegment, ArrayObjectVariable, ArrayStringSegment
66
from core.workflow.entities.node_entities import NodeRunResult
77
from core.workflow.nodes.base import BaseNode
88
from core.workflow.nodes.enums import NodeType
@@ -37,10 +37,20 @@ def _run(self):
3737
process_data=process_data,
3838
outputs=outputs,
3939
)
40+
# tricky to handle the ArrayObjectVariable, fix issue #10596, because of that iteration node output,
41+
# is object and can not have files for now but the output can be File, so using this tricky way to
42+
# handle this, FIXME when refactor the iteration node can drop this code.
43+
if isinstance(variable, ArrayObjectVariable):
44+
files = []
45+
for item in variable.value:
46+
if isinstance(item, dict) and item.get("dify_model_identity") == FILE_MODEL_IDENTITY:
47+
file = File.model_validate(item)
48+
files.append(file)
49+
variable = ArrayFileSegment(value=files)
4050
if not isinstance(variable, ArrayFileSegment | ArrayNumberSegment | ArrayStringSegment):
4151
error_message = (
4252
f"Variable {self.node_data.variable} is not an ArrayFileSegment, ArrayNumberSegment "
43-
"or ArrayStringSegment"
53+
", ArrayStringSegment or ArrayObjectVariable."
4454
)
4555
return NodeRunResult(
4656
status=WorkflowNodeExecutionStatus.FAILED, error=error_message, inputs=inputs, outputs=outputs

0 commit comments

Comments
 (0)