mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-12 01:29:01 +08:00
fix: Update variable handling in VariableAssignerNode and clean up app_dsl_service (#12672)
Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
parent
9a6b1dc3a1
commit
c700364e1c
@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
from collections.abc import Sequence
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
from core.variables import SegmentType, Variable
|
from core.variables import SegmentType, Variable
|
||||||
@ -31,7 +32,7 @@ class VariableAssignerNode(BaseNode[VariableAssignerNodeData]):
|
|||||||
inputs = self.node_data.model_dump()
|
inputs = self.node_data.model_dump()
|
||||||
process_data: dict[str, Any] = {}
|
process_data: dict[str, Any] = {}
|
||||||
# NOTE: This node has no outputs
|
# NOTE: This node has no outputs
|
||||||
updated_variables: list[Variable] = []
|
updated_variable_selectors: list[Sequence[str]] = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
for item in self.node_data.items:
|
for item in self.node_data.items:
|
||||||
@ -98,7 +99,8 @@ class VariableAssignerNode(BaseNode[VariableAssignerNodeData]):
|
|||||||
value=item.value,
|
value=item.value,
|
||||||
)
|
)
|
||||||
variable = variable.model_copy(update={"value": updated_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:
|
except VariableOperatorNodeError as e:
|
||||||
return NodeRunResult(
|
return NodeRunResult(
|
||||||
status=WorkflowNodeExecutionStatus.FAILED,
|
status=WorkflowNodeExecutionStatus.FAILED,
|
||||||
@ -107,9 +109,15 @@ class VariableAssignerNode(BaseNode[VariableAssignerNodeData]):
|
|||||||
error=str(e),
|
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
|
# Update variables
|
||||||
for variable in updated_variables:
|
for selector in updated_variable_selectors:
|
||||||
self.graph_runtime_state.variable_pool.add(variable.selector, variable)
|
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
|
process_data[variable.name] = variable.value
|
||||||
|
|
||||||
if variable.selector[0] == CONVERSATION_VARIABLE_NODE_ID:
|
if variable.selector[0] == CONVERSATION_VARIABLE_NODE_ID:
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import logging
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
from enum import StrEnum
|
from enum import StrEnum
|
||||||
from typing import Optional, cast
|
from typing import Optional
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
|
||||||
@ -139,15 +139,6 @@ class AppDslService:
|
|||||||
status=ImportStatus.FAILED,
|
status=ImportStatus.FAILED,
|
||||||
error="Empty content from url",
|
error="Empty content from url",
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
content = cast(bytes, content).decode("utf-8")
|
|
||||||
except UnicodeDecodeError as e:
|
|
||||||
return Import(
|
|
||||||
id=import_id,
|
|
||||||
status=ImportStatus.FAILED,
|
|
||||||
error=f"Error decoding content: {e}",
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
return Import(
|
return Import(
|
||||||
id=import_id,
|
id=import_id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user