mirror of
https://github.com/langgenius/dify.git
synced 2026-04-25 17:47:30 +08:00
refactor(workflow): remove redundant get_base_node_data() method (#28803)
This commit is contained in:
parent
6f927b4a62
commit
dd3b1ccd45
@ -240,23 +240,23 @@ class Node(Generic[NodeDataT]):
|
|||||||
from core.workflow.nodes.tool.tool_node import ToolNode
|
from core.workflow.nodes.tool.tool_node import ToolNode
|
||||||
|
|
||||||
if isinstance(self, ToolNode):
|
if isinstance(self, ToolNode):
|
||||||
start_event.provider_id = getattr(self.get_base_node_data(), "provider_id", "")
|
start_event.provider_id = getattr(self.node_data, "provider_id", "")
|
||||||
start_event.provider_type = getattr(self.get_base_node_data(), "provider_type", "")
|
start_event.provider_type = getattr(self.node_data, "provider_type", "")
|
||||||
|
|
||||||
from core.workflow.nodes.datasource.datasource_node import DatasourceNode
|
from core.workflow.nodes.datasource.datasource_node import DatasourceNode
|
||||||
|
|
||||||
if isinstance(self, DatasourceNode):
|
if isinstance(self, DatasourceNode):
|
||||||
plugin_id = getattr(self.get_base_node_data(), "plugin_id", "")
|
plugin_id = getattr(self.node_data, "plugin_id", "")
|
||||||
provider_name = getattr(self.get_base_node_data(), "provider_name", "")
|
provider_name = getattr(self.node_data, "provider_name", "")
|
||||||
|
|
||||||
start_event.provider_id = f"{plugin_id}/{provider_name}"
|
start_event.provider_id = f"{plugin_id}/{provider_name}"
|
||||||
start_event.provider_type = getattr(self.get_base_node_data(), "provider_type", "")
|
start_event.provider_type = getattr(self.node_data, "provider_type", "")
|
||||||
|
|
||||||
from core.workflow.nodes.trigger_plugin.trigger_event_node import TriggerEventNode
|
from core.workflow.nodes.trigger_plugin.trigger_event_node import TriggerEventNode
|
||||||
|
|
||||||
if isinstance(self, TriggerEventNode):
|
if isinstance(self, TriggerEventNode):
|
||||||
start_event.provider_id = getattr(self.get_base_node_data(), "provider_id", "")
|
start_event.provider_id = getattr(self.node_data, "provider_id", "")
|
||||||
start_event.provider_type = getattr(self.get_base_node_data(), "provider_type", "")
|
start_event.provider_type = getattr(self.node_data, "provider_type", "")
|
||||||
|
|
||||||
from typing import cast
|
from typing import cast
|
||||||
|
|
||||||
@ -265,7 +265,7 @@ class Node(Generic[NodeDataT]):
|
|||||||
|
|
||||||
if isinstance(self, AgentNode):
|
if isinstance(self, AgentNode):
|
||||||
start_event.agent_strategy = AgentNodeStrategyInit(
|
start_event.agent_strategy = AgentNodeStrategyInit(
|
||||||
name=cast(AgentNodeData, self.get_base_node_data()).agent_strategy_name,
|
name=cast(AgentNodeData, self.node_data).agent_strategy_name,
|
||||||
icon=self.agent_strategy_icon,
|
icon=self.agent_strategy_icon,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -419,10 +419,6 @@ class Node(Generic[NodeDataT]):
|
|||||||
"""Get the default values dictionary for this node."""
|
"""Get the default values dictionary for this node."""
|
||||||
return self._node_data.default_value_dict
|
return self._node_data.default_value_dict
|
||||||
|
|
||||||
def get_base_node_data(self) -> BaseNodeData:
|
|
||||||
"""Get the BaseNodeData object for this node."""
|
|
||||||
return self._node_data
|
|
||||||
|
|
||||||
# Public interface properties that delegate to abstract methods
|
# Public interface properties that delegate to abstract methods
|
||||||
@property
|
@property
|
||||||
def error_strategy(self) -> ErrorStrategy | None:
|
def error_strategy(self) -> ErrorStrategy | None:
|
||||||
@ -548,7 +544,7 @@ class Node(Generic[NodeDataT]):
|
|||||||
id=self._node_execution_id,
|
id=self._node_execution_id,
|
||||||
node_id=self._node_id,
|
node_id=self._node_id,
|
||||||
node_type=self.node_type,
|
node_type=self.node_type,
|
||||||
node_title=self.get_base_node_data().title,
|
node_title=self.node_data.title,
|
||||||
start_at=event.start_at,
|
start_at=event.start_at,
|
||||||
inputs=event.inputs,
|
inputs=event.inputs,
|
||||||
metadata=event.metadata,
|
metadata=event.metadata,
|
||||||
@ -561,7 +557,7 @@ class Node(Generic[NodeDataT]):
|
|||||||
id=self._node_execution_id,
|
id=self._node_execution_id,
|
||||||
node_id=self._node_id,
|
node_id=self._node_id,
|
||||||
node_type=self.node_type,
|
node_type=self.node_type,
|
||||||
node_title=self.get_base_node_data().title,
|
node_title=self.node_data.title,
|
||||||
index=event.index,
|
index=event.index,
|
||||||
pre_loop_output=event.pre_loop_output,
|
pre_loop_output=event.pre_loop_output,
|
||||||
)
|
)
|
||||||
@ -572,7 +568,7 @@ class Node(Generic[NodeDataT]):
|
|||||||
id=self._node_execution_id,
|
id=self._node_execution_id,
|
||||||
node_id=self._node_id,
|
node_id=self._node_id,
|
||||||
node_type=self.node_type,
|
node_type=self.node_type,
|
||||||
node_title=self.get_base_node_data().title,
|
node_title=self.node_data.title,
|
||||||
start_at=event.start_at,
|
start_at=event.start_at,
|
||||||
inputs=event.inputs,
|
inputs=event.inputs,
|
||||||
outputs=event.outputs,
|
outputs=event.outputs,
|
||||||
@ -586,7 +582,7 @@ class Node(Generic[NodeDataT]):
|
|||||||
id=self._node_execution_id,
|
id=self._node_execution_id,
|
||||||
node_id=self._node_id,
|
node_id=self._node_id,
|
||||||
node_type=self.node_type,
|
node_type=self.node_type,
|
||||||
node_title=self.get_base_node_data().title,
|
node_title=self.node_data.title,
|
||||||
start_at=event.start_at,
|
start_at=event.start_at,
|
||||||
inputs=event.inputs,
|
inputs=event.inputs,
|
||||||
outputs=event.outputs,
|
outputs=event.outputs,
|
||||||
@ -601,7 +597,7 @@ class Node(Generic[NodeDataT]):
|
|||||||
id=self._node_execution_id,
|
id=self._node_execution_id,
|
||||||
node_id=self._node_id,
|
node_id=self._node_id,
|
||||||
node_type=self.node_type,
|
node_type=self.node_type,
|
||||||
node_title=self.get_base_node_data().title,
|
node_title=self.node_data.title,
|
||||||
start_at=event.start_at,
|
start_at=event.start_at,
|
||||||
inputs=event.inputs,
|
inputs=event.inputs,
|
||||||
metadata=event.metadata,
|
metadata=event.metadata,
|
||||||
@ -614,7 +610,7 @@ class Node(Generic[NodeDataT]):
|
|||||||
id=self._node_execution_id,
|
id=self._node_execution_id,
|
||||||
node_id=self._node_id,
|
node_id=self._node_id,
|
||||||
node_type=self.node_type,
|
node_type=self.node_type,
|
||||||
node_title=self.get_base_node_data().title,
|
node_title=self.node_data.title,
|
||||||
index=event.index,
|
index=event.index,
|
||||||
pre_iteration_output=event.pre_iteration_output,
|
pre_iteration_output=event.pre_iteration_output,
|
||||||
)
|
)
|
||||||
@ -625,7 +621,7 @@ class Node(Generic[NodeDataT]):
|
|||||||
id=self._node_execution_id,
|
id=self._node_execution_id,
|
||||||
node_id=self._node_id,
|
node_id=self._node_id,
|
||||||
node_type=self.node_type,
|
node_type=self.node_type,
|
||||||
node_title=self.get_base_node_data().title,
|
node_title=self.node_data.title,
|
||||||
start_at=event.start_at,
|
start_at=event.start_at,
|
||||||
inputs=event.inputs,
|
inputs=event.inputs,
|
||||||
outputs=event.outputs,
|
outputs=event.outputs,
|
||||||
@ -639,7 +635,7 @@ class Node(Generic[NodeDataT]):
|
|||||||
id=self._node_execution_id,
|
id=self._node_execution_id,
|
||||||
node_id=self._node_id,
|
node_id=self._node_id,
|
||||||
node_type=self.node_type,
|
node_type=self.node_type,
|
||||||
node_title=self.get_base_node_data().title,
|
node_title=self.node_data.title,
|
||||||
start_at=event.start_at,
|
start_at=event.start_at,
|
||||||
inputs=event.inputs,
|
inputs=event.inputs,
|
||||||
outputs=event.outputs,
|
outputs=event.outputs,
|
||||||
|
|||||||
@ -744,7 +744,7 @@ def test_graph_run_emits_partial_success_when_node_failure_recovered():
|
|||||||
)
|
)
|
||||||
|
|
||||||
llm_node = graph.nodes["llm"]
|
llm_node = graph.nodes["llm"]
|
||||||
base_node_data = llm_node.get_base_node_data()
|
base_node_data = llm_node.node_data
|
||||||
base_node_data.error_strategy = ErrorStrategy.DEFAULT_VALUE
|
base_node_data.error_strategy = ErrorStrategy.DEFAULT_VALUE
|
||||||
base_node_data.default_value = [DefaultValue(key="text", value="fallback response", type=DefaultValueType.STRING)]
|
base_node_data.default_value = [DefaultValue(key="text", value="fallback response", type=DefaultValueType.STRING)]
|
||||||
|
|
||||||
|
|||||||
@ -471,8 +471,8 @@ class TestCodeNodeInitialization:
|
|||||||
|
|
||||||
assert node._get_description() is None
|
assert node._get_description() is None
|
||||||
|
|
||||||
def test_get_base_node_data(self):
|
def test_node_data_property(self):
|
||||||
"""Test get_base_node_data returns node data."""
|
"""Test node_data property returns node data."""
|
||||||
node = CodeNode.__new__(CodeNode)
|
node = CodeNode.__new__(CodeNode)
|
||||||
node._node_data = CodeNodeData(
|
node._node_data = CodeNodeData(
|
||||||
title="Base Test",
|
title="Base Test",
|
||||||
@ -482,7 +482,7 @@ class TestCodeNodeInitialization:
|
|||||||
outputs={},
|
outputs={},
|
||||||
)
|
)
|
||||||
|
|
||||||
result = node.get_base_node_data()
|
result = node.node_data
|
||||||
|
|
||||||
assert result == node._node_data
|
assert result == node._node_data
|
||||||
assert result.title == "Base Test"
|
assert result.title == "Base Test"
|
||||||
|
|||||||
@ -240,8 +240,8 @@ class TestIterationNodeInitialization:
|
|||||||
|
|
||||||
assert node._get_description() == "This is a description"
|
assert node._get_description() == "This is a description"
|
||||||
|
|
||||||
def test_get_base_node_data(self):
|
def test_node_data_property(self):
|
||||||
"""Test get_base_node_data returns node data."""
|
"""Test node_data property returns node data."""
|
||||||
node = IterationNode.__new__(IterationNode)
|
node = IterationNode.__new__(IterationNode)
|
||||||
node._node_data = IterationNodeData(
|
node._node_data = IterationNodeData(
|
||||||
title="Base Test",
|
title="Base Test",
|
||||||
@ -249,7 +249,7 @@ class TestIterationNodeInitialization:
|
|||||||
output_selector=["y"],
|
output_selector=["y"],
|
||||||
)
|
)
|
||||||
|
|
||||||
result = node.get_base_node_data()
|
result = node.node_data
|
||||||
|
|
||||||
assert result == node._node_data
|
assert result == node._node_data
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user