mirror of https://github.com/langgenius/dify.git
fix: conversation var unexpected reset after HITL node (#32936)
This commit is contained in:
parent
ad81513b6a
commit
7ffa6c1849
|
|
@ -65,9 +65,15 @@ class VariablePool(BaseModel):
|
||||||
# Add environment variables to the variable pool
|
# Add environment variables to the variable pool
|
||||||
for var in self.environment_variables:
|
for var in self.environment_variables:
|
||||||
self.add((ENVIRONMENT_VARIABLE_NODE_ID, var.name), var)
|
self.add((ENVIRONMENT_VARIABLE_NODE_ID, var.name), var)
|
||||||
# Add conversation variables to the variable pool
|
# Add conversation variables to the variable pool. When restoring from a serialized
|
||||||
|
# snapshot, `variable_dictionary` already carries the latest runtime values.
|
||||||
|
# In that case, keep existing entries instead of overwriting them with the
|
||||||
|
# bootstrap list.
|
||||||
for var in self.conversation_variables:
|
for var in self.conversation_variables:
|
||||||
self.add((CONVERSATION_VARIABLE_NODE_ID, var.name), var)
|
selector = (CONVERSATION_VARIABLE_NODE_ID, var.name)
|
||||||
|
if self._has(selector):
|
||||||
|
continue
|
||||||
|
self.add(selector, var)
|
||||||
# Add rag pipeline variables to the variable pool
|
# Add rag pipeline variables to the variable pool
|
||||||
if self.rag_pipeline_variables:
|
if self.rag_pipeline_variables:
|
||||||
rag_pipeline_variables_map: defaultdict[Any, dict[Any, Any]] = defaultdict(dict)
|
rag_pipeline_variables_map: defaultdict[Any, dict[Any, Any]] = defaultdict(dict)
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,10 @@ from unittest.mock import MagicMock, patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
from dify_graph.constants import CONVERSATION_VARIABLE_NODE_ID
|
||||||
from dify_graph.model_runtime.entities.llm_entities import LLMUsage
|
from dify_graph.model_runtime.entities.llm_entities import LLMUsage
|
||||||
from dify_graph.runtime import GraphRuntimeState, ReadOnlyGraphRuntimeStateWrapper, VariablePool
|
from dify_graph.runtime import GraphRuntimeState, ReadOnlyGraphRuntimeStateWrapper, VariablePool
|
||||||
|
from dify_graph.variables.variables import StringVariable
|
||||||
|
|
||||||
|
|
||||||
class StubCoordinator:
|
class StubCoordinator:
|
||||||
|
|
@ -278,3 +280,17 @@ class TestGraphRuntimeState:
|
||||||
assert restored_execution.started is True
|
assert restored_execution.started is True
|
||||||
|
|
||||||
assert new_stub.state == "configured"
|
assert new_stub.state == "configured"
|
||||||
|
|
||||||
|
def test_snapshot_restore_preserves_updated_conversation_variable(self):
|
||||||
|
variable_pool = VariablePool(
|
||||||
|
conversation_variables=[StringVariable(name="session_name", value="before")],
|
||||||
|
)
|
||||||
|
variable_pool.add((CONVERSATION_VARIABLE_NODE_ID, "session_name"), "after")
|
||||||
|
|
||||||
|
state = GraphRuntimeState(variable_pool=variable_pool, start_at=time())
|
||||||
|
snapshot = state.dumps()
|
||||||
|
restored = GraphRuntimeState.from_snapshot(snapshot)
|
||||||
|
|
||||||
|
restored_value = restored.variable_pool.get((CONVERSATION_VARIABLE_NODE_ID, "session_name"))
|
||||||
|
assert restored_value is not None
|
||||||
|
assert restored_value.value == "after"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue