| from flask import Flask, current_app | from flask import Flask, current_app | ||||
| from configs import dify_config | from configs import dify_config | ||||
| from core.variables import ArrayVariable, IntegerVariable, NoneVariable | |||||
| from core.variables import IntegerVariable, NoneSegment | |||||
| from core.variables.segments import ArrayAnySegment, ArraySegment | from core.variables.segments import ArrayAnySegment, ArraySegment | ||||
| from core.workflow.entities.node_entities import ( | from core.workflow.entities.node_entities import ( | ||||
| NodeRunResult, | NodeRunResult, | ||||
| if not variable: | if not variable: | ||||
| raise IteratorVariableNotFoundError(f"iterator variable {self._node_data.iterator_selector} not found") | raise IteratorVariableNotFoundError(f"iterator variable {self._node_data.iterator_selector} not found") | ||||
| if not isinstance(variable, ArrayVariable) and not isinstance(variable, NoneVariable): | |||||
| if not isinstance(variable, ArraySegment) and not isinstance(variable, NoneSegment): | |||||
| raise InvalidIteratorValueError(f"invalid iterator value: {variable}, please provide a list.") | raise InvalidIteratorValueError(f"invalid iterator value: {variable}, please provide a list.") | ||||
| if isinstance(variable, NoneVariable) or len(variable.value) == 0: | |||||
| if isinstance(variable, NoneSegment) or len(variable.value) == 0: | |||||
| # Try our best to preserve the type informat. | # Try our best to preserve the type informat. | ||||
| if isinstance(variable, ArraySegment): | if isinstance(variable, ArraySegment): | ||||
| output = variable.model_copy(update={"value": []}) | output = variable.model_copy(update={"value": []}) |