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.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix(api): add `trigger_info` to WorkflowNodeExecutionMetadataKey (#33753)
QuantumGhostc93289e93c31
diff --git a/api/core/trigger/constants.py b/api/core/trigger/constants.pyindex bfa45c3f2b6..192faa2d3ea 100644--- a/api/core/trigger/constants.py+++ b/api/core/trigger/constants.py@@ -3,7 +3,6 @@ from typing import FinalTRIGGER_WEBHOOK_NODE_TYPE: Final[str] = "trigger-webhook"TRIGGER_SCHEDULE_NODE_TYPE: Final[str] = "trigger-schedule"TRIGGER_PLUGIN_NODE_TYPE: Final[str] = "trigger-plugin"-TRIGGER_INFO_METADATA_KEY: Final[str] = "trigger_info"TRIGGER_NODE_TYPES: Final[frozenset[str]] = frozenset({diff --git a/api/core/workflow/nodes/trigger_plugin/trigger_event_node.py b/api/core/workflow/nodes/trigger_plugin/trigger_event_node.pyindex 2048a530642..118c2f2668b 100644--- a/api/core/workflow/nodes/trigger_plugin/trigger_event_node.py+++ b/api/core/workflow/nodes/trigger_plugin/trigger_event_node.py@@ -1,7 +1,7 @@from collections.abc import Mapping-from typing import Any, cast+from typing import Any-from core.trigger.constants import TRIGGER_INFO_METADATA_KEY, TRIGGER_PLUGIN_NODE_TYPE+from core.trigger.constants import TRIGGER_PLUGIN_NODE_TYPEfrom dify_graph.constants import SYSTEM_VARIABLE_NODE_IDfrom dify_graph.entities.workflow_node_execution import WorkflowNodeExecutionStatusfrom dify_graph.enums import NodeExecutionType, WorkflowNodeExecutionMetadataKey@@ -47,7 +47,7 @@ class TriggerEventNode(Node[TriggerEventNodeData]):# Get trigger data passed when workflow was triggeredmetadata: dict[WorkflowNodeExecutionMetadataKey, Any] = {- cast(WorkflowNodeExecutionMetadataKey, TRIGGER_INFO_METADATA_KEY): {+ WorkflowNodeExecutionMetadataKey.TRIGGER_INFO: {"provider_id": self.node_data.provider_id,"event_name": self.node_data.event_name,"plugin_unique_identifier": self.node_data.plugin_unique_identifier,diff --git a/api/dify_graph/enums.py b/api/dify_graph/enums.pyindex 06653bebb61..cfb135cbb0f 100644--- a/api/dify_graph/enums.py+++ b/api/dify_graph/enums.py@@ -245,6 +245,9 @@ _END_STATE = frozenset(class WorkflowNodeExecutionMetadataKey(StrEnum):"""Node Run Metadata Key.++ Values in this enum are persisted as execution metadata and must stay in sync+ with every node that writes `NodeRunResult.metadata`."""TOTAL_TOKENS = "total_tokens"@@ -266,6 +269,7 @@ class WorkflowNodeExecutionMetadataKey(StrEnum):ERROR_STRATEGY = "error_strategy" # node in continue on error mode return the fieldLOOP_VARIABLE_MAP = "loop_variable_map" # single loop variable outputDATASOURCE_INFO = "datasource_info"+ TRIGGER_INFO = "trigger_info"COMPLETED_REASON = "completed_reason" # completed reason for loop nodediff --git a/api/models/workflow.py b/api/models/workflow.pyindex 9bb249481fa..e7b20d0e659 100644--- a/api/models/workflow.py+++ b/api/models/workflow.py@@ -22,14 +22,14 @@ from sqlalchemy import (from sqlalchemy.orm import Mapped, mapped_columnfrom typing_extensions import deprecated-from core.trigger.constants import TRIGGER_INFO_METADATA_KEY, TRIGGER_PLUGIN_NODE_TYPE+from core.trigger.constants import TRIGGER_PLUGIN_NODE_TYPEfrom dify_graph.constants import (CONVERSATION_VARIABLE_NODE_ID,SYSTEM_VARIABLE_NODE_ID,)from dify_graph.entities.graph_config import NodeConfigDict, NodeConfigDictAdapterfrom dify_graph.entities.pause_reason import HumanInputRequired, PauseReason, PauseReasonType, SchedulingPause-from dify_graph.enums import BuiltinNodeTypes, NodeType, WorkflowExecutionStatus+from dify_graph.enums import BuiltinNodeTypes, NodeType, WorkflowExecutionStatus, WorkflowNodeExecutionMetadataKeyfrom dify_graph.file.constants import maybe_file_objectfrom dify_graph.file.models import Filefrom dify_graph.variables import utils as variable_utils@@ -936,8 +936,11 @@ class WorkflowNodeExecutionModel(Base): # This model is expected to have `offloelif self.node_type == BuiltinNodeTypes.DATASOURCE and "datasource_info" in execution_metadata:datasource_info = execution_metadata["datasource_info"]extras["icon"] = datasource_info.get("icon")- elif self.node_type == TRIGGER_PLUGIN_NODE_TYPE and TRIGGER_INFO_METADATA_KEY in execution_metadata:- trigger_info = execution_metadata[TRIGGER_INFO_METADATA_KEY] or {}+ elif (+ self.node_type == TRIGGER_PLUGIN_NODE_TYPE+ and WorkflowNodeExecutionMetadataKey.TRIGGER_INFO in execution_metadata+ ):+ trigger_info = execution_metadata[WorkflowNodeExecutionMetadataKey.TRIGGER_INFO] or {}provider_id = trigger_info.get("provider_id")if provider_id:extras["icon"] = TriggerManager.get_trigger_plugin_icon(diff --git a/api/tests/unit_tests/core/workflow/nodes/trigger_plugin/test_trigger_event_node.py b/api/tests/unit_tests/core/workflow/nodes/trigger_plugin/test_trigger_event_node.pynew file mode 100644index 00000000000..9aeab0409e4--- /dev/null+++ b/api/tests/unit_tests/core/workflow/nodes/trigger_plugin/test_trigger_event_node.py@@ -0,0 +1,63 @@+from collections.abc import Mapping++from core.trigger.constants import TRIGGER_PLUGIN_NODE_TYPE+from core.workflow.nodes.trigger_plugin.trigger_event_node import TriggerEventNode+from dify_graph.entities import GraphInitParams+from dify_graph.entities.graph_config import NodeConfigDict, NodeConfigDictAdapter+from dify_graph.enums import WorkflowNodeExecutionMetadataKey, WorkflowNodeExecutionStatus+from dify_graph.runtime import GraphRuntimeState, VariablePool+from dify_graph.system_variable import SystemVariable+from tests.workflow_test_utils import build_test_graph_init_params+++def _build_context(graph_config: Mapping[str, object]) -> tuple[GraphInitParams, GraphRuntimeState]:+ init_params = build_test_graph_init_params(+ graph_config=graph_config,+ user_from="account",+ invoke_from="debugger",+ )+ runtime_state = GraphRuntimeState(+ variable_pool=VariablePool(+ system_variables=SystemVariable(user_id="user", files=[]),+ user_inputs={"payload": "value"},+ ),+ start_at=0.0,+ )+ return init_params, runtime_state+++def _build_node_config() -> NodeConfigDict:+ return NodeConfigDictAdapter.validate_python(+ {+ "id": "node-1",+ "data": {+ "type": TRIGGER_PLUGIN_NODE_TYPE,+ "title": "Trigger Event",+ "plugin_id": "plugin-id",+ "provider_id": "provider-id",+ "event_name": "event-name",+ "subscription_id": "subscription-id",+ "plugin_unique_identifier": "plugin-unique-identifier",+ "event_parameters": {},+ },+ }+ )+++def test_trigger_event_node_run_populates_trigger_info_metadata() -> None:+ init_params, runtime_state = _build_context(graph_config={})+ node = TriggerEventNode(+ id="node-1",+ config=_build_node_config(),+ graph_init_params=init_params,+ graph_runtime_state=runtime_state,+ )++ result = node._run()++ assert result.status == WorkflowNodeExecutionStatus.SUCCEEDED+ assert result.metadata[WorkflowNodeExecutionMetadataKey.TRIGGER_INFO] == {+ "provider_id": "provider-id",+ "event_name": "event-name",+ "plugin_unique_identifier": "plugin-unique-identifier",+ }diff --git a/api/tests/unit_tests/dify_graph/node_events/test_base.py b/api/tests/unit_tests/dify_graph/node_events/test_base.pynew file mode 100644index 00000000000..6d789abac0a--- /dev/null+++ b/api/tests/unit_tests/dify_graph/node_events/test_base.py@@ -0,0 +1,19 @@+from dify_graph.enums import WorkflowNodeExecutionMetadataKey, WorkflowNodeExecutionStatus+from dify_graph.node_events.base import NodeRunResult+++def test_node_run_result_accepts_trigger_info_metadata() -> None:+ result = NodeRunResult(+ status=WorkflowNodeExecutionStatus.SUCCEEDED,+ metadata={+ WorkflowNodeExecutionMetadataKey.TRIGGER_INFO: {+ "provider_id": "provider-id",+ "event_name": "event-name",+ }+ },+ )++ assert result.metadata[WorkflowNodeExecutionMetadataKey.TRIGGER_INFO] == {+ "provider_id": "provider-id",+ "event_name": "event-name",+ }