|
1 | 1 | from collections.abc import Callable, Sequence
|
2 | 2 | from typing import Literal, Union
|
3 | 3 |
|
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 |
6 | 6 | from core.workflow.entities.node_entities import NodeRunResult
|
7 | 7 | from core.workflow.nodes.base import BaseNode
|
8 | 8 | from core.workflow.nodes.enums import NodeType
|
@@ -37,10 +37,20 @@ def _run(self):
|
37 | 37 | process_data=process_data,
|
38 | 38 | outputs=outputs,
|
39 | 39 | )
|
| 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) |
40 | 50 | if not isinstance(variable, ArrayFileSegment | ArrayNumberSegment | ArrayStringSegment):
|
41 | 51 | error_message = (
|
42 | 52 | f"Variable {self.node_data.variable} is not an ArrayFileSegment, ArrayNumberSegment "
|
43 |
| - "or ArrayStringSegment" |
| 53 | + ", ArrayStringSegment or ArrayObjectVariable." |
44 | 54 | )
|
45 | 55 | return NodeRunResult(
|
46 | 56 | status=WorkflowNodeExecutionStatus.FAILED, error=error_message, inputs=inputs, outputs=outputs
|
|
0 commit comments