Skip to content

Commit f76437e

Browse files
laipz8200alexcodelf
authored andcommitted
fix: Update variable handling in VariableAssignerNode and clean up app_dsl_service (langgenius#12672)
Signed-off-by: -LAN- <laipz8200@outlook.com>
1 parent 3da29c7 commit f76437e

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

api/core/workflow/nodes/variable_assigner/v2/node.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from collections.abc import Sequence
23
from typing import Any, cast
34

45
from core.variables import SegmentType, Variable
@@ -31,7 +32,7 @@ def _run(self) -> NodeRunResult:
3132
inputs = self.node_data.model_dump()
3233
process_data: dict[str, Any] = {}
3334
# NOTE: This node has no outputs
34-
updated_variables: list[Variable] = []
35+
updated_variable_selectors: list[Sequence[str]] = []
3536

3637
try:
3738
for item in self.node_data.items:
@@ -98,7 +99,8 @@ def _run(self) -> NodeRunResult:
9899
value=item.value,
99100
)
100101
variable = variable.model_copy(update={"value": updated_value})
101-
updated_variables.append(variable)
102+
self.graph_runtime_state.variable_pool.add(variable.selector, variable)
103+
updated_variable_selectors.append(variable.selector)
102104
except VariableOperatorNodeError as e:
103105
return NodeRunResult(
104106
status=WorkflowNodeExecutionStatus.FAILED,
@@ -107,9 +109,15 @@ def _run(self) -> NodeRunResult:
107109
error=str(e),
108110
)
109111

112+
# The `updated_variable_selectors` is a list contains list[str] which not hashable,
113+
# remove the duplicated items first.
114+
updated_variable_selectors = list(set(map(tuple, updated_variable_selectors)))
115+
110116
# Update variables
111-
for variable in updated_variables:
112-
self.graph_runtime_state.variable_pool.add(variable.selector, variable)
117+
for selector in updated_variable_selectors:
118+
variable = self.graph_runtime_state.variable_pool.get(selector)
119+
if not isinstance(variable, Variable):
120+
raise VariableNotFoundError(variable_selector=selector)
113121
process_data[variable.name] = variable.value
114122

115123
if variable.selector[0] == CONVERSATION_VARIABLE_NODE_ID:

api/services/app_dsl_service.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22
import uuid
33
from enum import StrEnum
4-
from typing import Optional, cast
4+
from typing import Optional
55
from urllib.parse import urlparse
66
from uuid import uuid4
77

@@ -139,15 +139,6 @@ def import_app(
139139
status=ImportStatus.FAILED,
140140
error="Empty content from url",
141141
)
142-
143-
try:
144-
content = cast(bytes, content).decode("utf-8")
145-
except UnicodeDecodeError as e:
146-
return Import(
147-
id=import_id,
148-
status=ImportStatus.FAILED,
149-
error=f"Error decoding content: {e}",
150-
)
151142
except Exception as e:
152143
return Import(
153144
id=import_id,

0 commit comments

Comments
 (0)