|
@@ -1,4 +1,5 @@
|
|
|
import json
|
|
|
+from collections.abc import Sequence
|
|
|
from typing import Any, cast
|
|
|
|
|
|
from core.variables import SegmentType, Variable
|
|
@@ -31,7 +32,7 @@ class VariableAssignerNode(BaseNode[VariableAssignerNodeData]):
|
|
|
inputs = self.node_data.model_dump()
|
|
|
process_data: dict[str, Any] = {}
|
|
|
# NOTE: This node has no outputs
|
|
|
- updated_variables: list[Variable] = []
|
|
|
+ updated_variable_selectors: list[Sequence[str]] = []
|
|
|
|
|
|
try:
|
|
|
for item in self.node_data.items:
|
|
@@ -98,7 +99,8 @@ class VariableAssignerNode(BaseNode[VariableAssignerNodeData]):
|
|
|
value=item.value,
|
|
|
)
|
|
|
variable = variable.model_copy(update={"value": updated_value})
|
|
|
- updated_variables.append(variable)
|
|
|
+ self.graph_runtime_state.variable_pool.add(variable.selector, variable)
|
|
|
+ updated_variable_selectors.append(variable.selector)
|
|
|
except VariableOperatorNodeError as e:
|
|
|
return NodeRunResult(
|
|
|
status=WorkflowNodeExecutionStatus.FAILED,
|
|
@@ -107,9 +109,15 @@ class VariableAssignerNode(BaseNode[VariableAssignerNodeData]):
|
|
|
error=str(e),
|
|
|
)
|
|
|
|
|
|
+ # The `updated_variable_selectors` is a list contains list[str] which not hashable,
|
|
|
+ # remove the duplicated items first.
|
|
|
+ updated_variable_selectors = list(set(map(tuple, updated_variable_selectors)))
|
|
|
+
|
|
|
# Update variables
|
|
|
- for variable in updated_variables:
|
|
|
- self.graph_runtime_state.variable_pool.add(variable.selector, variable)
|
|
|
+ for selector in updated_variable_selectors:
|
|
|
+ variable = self.graph_runtime_state.variable_pool.get(selector)
|
|
|
+ if not isinstance(variable, Variable):
|
|
|
+ raise VariableNotFoundError(variable_selector=selector)
|
|
|
process_data[variable.name] = variable.value
|
|
|
|
|
|
if variable.selector[0] == CONVERSATION_VARIABLE_NODE_ID:
|