Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

fix(workflow): handle NoneSegments in variable extraction (#9585)

-LAN-2e657b7b1291
diff --git a/api/core/workflow/nodes/llm/node.py b/api/core/workflow/nodes/llm/node.py
index f310a67b76e..4179d34f9a1 100644
--- a/api/core/workflow/nodes/llm/node.py
+++ b/api/core/workflow/nodes/llm/node.py
@@ -22,7 +22,7 @@ from core.model_runtime.utils.encoders import jsonable_encoder
from core.prompt.advanced_prompt_transform import AdvancedPromptTransform
from core.prompt.entities.advanced_prompt_entities import CompletionModelPromptTemplate, MemoryConfig
from core.prompt.utils.prompt_message_util import PromptMessageUtil
-from core.variables import ArrayAnySegment, ArrayFileSegment, FileSegment
+from core.variables import ArrayAnySegment, ArrayFileSegment, FileSegment, NoneSegment
from core.workflow.constants import SYSTEM_VARIABLE_NODE_ID
from core.workflow.entities.node_entities import NodeRunMetadataKey, NodeRunResult
from core.workflow.enums import SystemVariableKey
@@ -320,11 +320,12 @@ class LLMNode(BaseNode[LLMNodeData]):
variable_selectors = variable_template_parser.extract_variable_selectors()
for variable_selector in variable_selectors:
- variable_value = self.graph_runtime_state.variable_pool.get(variable_selector.value_selector)
- if variable_value is None:
+ variable = self.graph_runtime_state.variable_pool.get(variable_selector.value_selector)
+ if variable is None:
raise ValueError(f"Variable {variable_selector.variable} not found")
-
- inputs[variable_selector.variable] = variable_value.to_object()
+ if isinstance(variable, NoneSegment):
+ continue
+ inputs[variable_selector.variable] = variable.to_object()
memory = node_data.memory
if memory and memory.query_prompt_template:
@@ -332,11 +333,12 @@ class LLMNode(BaseNode[LLMNodeData]):
template=memory.query_prompt_template
).extract_variable_selectors()
for variable_selector in query_variable_selectors:
- variable_value = self.graph_runtime_state.variable_pool.get(variable_selector.value_selector)
- if variable_value is None:
+ variable = self.graph_runtime_state.variable_pool.get(variable_selector.value_selector)
+ if variable is None:
raise ValueError(f"Variable {variable_selector.variable} not found")
-
- inputs[variable_selector.variable] = variable_value.to_object()
+ if isinstance(variable, NoneSegment):
+ continue
+ inputs[variable_selector.variable] = variable.to_object()
return inputs