Skip to content

fix(api): add trigger_info to WorkflowNodeExecutionMetadataKey#33753

Merged
fatelei merged 4 commits intolanggenius:mainfrom
QuantumGhost:vk/4ef0-
Mar 19, 2026
Merged

fix(api): add trigger_info to WorkflowNodeExecutionMetadataKey#33753
fatelei merged 4 commits intolanggenius:mainfrom
QuantumGhost:vk/4ef0-

Conversation

@QuantumGhost
Copy link
Collaborator

@QuantumGhost QuantumGhost commented Mar 19, 2026

Summary

This PR fixes a NodeRunResult.metadata validation failure caused by the trigger plugin node writing trigger_info as a metadata key before that key was registered in WorkflowNodeExecutionMetadataKey.

It also removes the standalone TRIGGER_INFO_METADATA_KEY constant and standardizes all trigger metadata access through WorkflowNodeExecutionMetadataKey.TRIGGER_INFO.

Root Cause

NodeRunResult.metadata is validated against WorkflowNodeExecutionMetadataKey.

The trigger plugin node wrote:

  • trigger_info

but WorkflowNodeExecutionMetadataKey did not include that value yet.

As a result, Pydantic rejected the metadata payload when constructing NodeRunResult, causing workflow execution to fail for trigger plugin nodes.

Changes

Fix metadata validation

  • Add TRIGGER_INFO to WorkflowNodeExecutionMetadataKey
  • Update trigger plugin node metadata writing to use WorkflowNodeExecutionMetadataKey.TRIGGER_INFO

Standardize metadata key usage

  • Replace remaining usages of TRIGGER_INFO_METADATA_KEY with WorkflowNodeExecutionMetadataKey.TRIGGER_INFO
  • Remove the TRIGGER_INFO_METADATA_KEY constant from core.trigger.constants

Tests

  • Add a minimal model-level test to verify NodeRunResult accepts trigger metadata under WorkflowNodeExecutionMetadataKey.TRIGGER_INFO
  • Keep a trigger plugin node regression test to verify the node populates trigger metadata correctly

Fix #33754

Screenshots

Before After
image ...

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint and make type-check (backend) and cd web && npx lint-staged (frontend) to appease the lint gods

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the handling of trigger event information within the workflow execution metadata. It introduces a new, explicit enum member for trigger details, ensuring a standardized and type-safe approach to storing this critical data. The changes improve code clarity and maintainability by removing unnecessary type casting and are backed by new unit tests to validate the correct behavior.

Highlights

  • Standardized Trigger Info Metadata: Introduced a dedicated TRIGGER_INFO member to the WorkflowNodeExecutionMetadataKey enum for consistent storage of trigger event details.
  • Refactored Trigger Event Node: Updated the TriggerEventNode to directly use the new TRIGGER_INFO enum member, removing a type cast.
  • Enhanced Documentation: Added a docstring to WorkflowNodeExecutionMetadataKey to clarify that its values are persisted and must remain in sync.
  • Comprehensive Testing: Added new unit tests to ensure the TriggerEventNode correctly populates TRIGGER_INFO metadata and that NodeRunResult properly accepts this metadata.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-19 09:26:28.513816537 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-19 09:26:18.563694658 +0000
@@ -5249,6 +5249,8 @@
    --> tests/unit_tests/core/workflow/nodes/tool/test_tool_node.py:105:22
 ERROR Argument `Generator[NodeEventBase, None, LLMUsage]` is not assignable to parameter `generator` with type `Generator[Unknown]` in function `_collect_events` [bad-argument-type]
    --> tests/unit_tests/core/workflow/nodes/tool/test_tool_node.py:113:32
+ERROR Cannot index into `Mapping[WorkflowNodeExecutionMetadataKey, Any]` [bad-index]
+  --> tests/unit_tests/core/workflow/nodes/trigger_plugin/test_trigger_event_node.py:59:28
 ERROR Argument `dict[str, dict[str, WriteMode | list[str] | str] | str]` is not assignable to parameter `config` with type `NodeConfigDict` in function `dify_graph.nodes.variable_assigner.v1.node.VariableAssignerNode.__init__` [bad-argument-type]
    --> tests/unit_tests/core/workflow/nodes/variable_assigner/v1/test_variable_assigner_v1.py:107:16
 ERROR Argument `dict[str, dict[str, WriteMode | list[str] | str] | str]` is not assignable to parameter `config` with type `NodeConfigDict` in function `dify_graph.nodes.variable_assigner.v1.node.VariableAssignerNode.__init__` [bad-argument-type]
@@ -5387,6 +5389,10 @@
    --> tests/unit_tests/dify_graph/model_runtime/utils/test_encoders.py:153:59
 ERROR No matching overload found for function `compile` called with arguments: (Literal['abc']) [no-matching-overload]
    --> tests/unit_tests/dify_graph/model_runtime/utils/test_encoders.py:181:40
+ERROR Argument `dict[str, Any]` is not assignable to parameter `metadata` with type `Mapping[WorkflowNodeExecutionMetadataKey, Any]` in function `dify_graph.node_events.base.NodeRunResult.__init__` [bad-argument-type]
+  --> tests/unit_tests/dify_graph/node_events/test_base.py:9:18
+ERROR Cannot index into `Mapping[WorkflowNodeExecutionMetadataKey, Any]` [bad-index]
+  --> tests/unit_tests/dify_graph/node_events/test_base.py:17:28
 ERROR Object of class `int` has no attribute `startswith` [missing-attribute]
   --> tests/unit_tests/extensions/otel/test_celery_sqlcommenter.py:25:16
 ERROR Cannot index into `object` [bad-index]

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the metadata key for trigger information into the WorkflowNodeExecutionMetadataKey enum, which improves type safety and code consistency. The changes are well-implemented, and new tests have been added to cover them. My feedback focuses on updating the new tests to use the newly introduced enum member for better consistency with the refactoring.

@github-actions
Copy link
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-03-19 09:28:27.337761361 +0000
+++ /tmp/pyrefly_pr.txt	2026-03-19 09:28:18.061753762 +0000
@@ -5249,6 +5249,8 @@
    --> tests/unit_tests/core/workflow/nodes/tool/test_tool_node.py:105:22
 ERROR Argument `Generator[NodeEventBase, None, LLMUsage]` is not assignable to parameter `generator` with type `Generator[Unknown]` in function `_collect_events` [bad-argument-type]
    --> tests/unit_tests/core/workflow/nodes/tool/test_tool_node.py:113:32
+ERROR Cannot index into `Mapping[WorkflowNodeExecutionMetadataKey, Any]` [bad-index]
+  --> tests/unit_tests/core/workflow/nodes/trigger_plugin/test_trigger_event_node.py:59:28
 ERROR Argument `dict[str, dict[str, WriteMode | list[str] | str] | str]` is not assignable to parameter `config` with type `NodeConfigDict` in function `dify_graph.nodes.variable_assigner.v1.node.VariableAssignerNode.__init__` [bad-argument-type]
    --> tests/unit_tests/core/workflow/nodes/variable_assigner/v1/test_variable_assigner_v1.py:107:16
 ERROR Argument `dict[str, dict[str, WriteMode | list[str] | str] | str]` is not assignable to parameter `config` with type `NodeConfigDict` in function `dify_graph.nodes.variable_assigner.v1.node.VariableAssignerNode.__init__` [bad-argument-type]
@@ -5387,6 +5389,10 @@
    --> tests/unit_tests/dify_graph/model_runtime/utils/test_encoders.py:153:59
 ERROR No matching overload found for function `compile` called with arguments: (Literal['abc']) [no-matching-overload]
    --> tests/unit_tests/dify_graph/model_runtime/utils/test_encoders.py:181:40
+ERROR Argument `dict[str, Any]` is not assignable to parameter `metadata` with type `Mapping[WorkflowNodeExecutionMetadataKey, Any]` in function `dify_graph.node_events.base.NodeRunResult.__init__` [bad-argument-type]
+  --> tests/unit_tests/dify_graph/node_events/test_base.py:9:18
+ERROR Cannot index into `Mapping[WorkflowNodeExecutionMetadataKey, Any]` [bad-index]
+  --> tests/unit_tests/dify_graph/node_events/test_base.py:17:28
 ERROR Object of class `int` has no attribute `startswith` [missing-attribute]
   --> tests/unit_tests/extensions/otel/test_celery_sqlcommenter.py:25:16
 ERROR Cannot index into `object` [bad-index]

@QuantumGhost QuantumGhost changed the title fix(api): fix(api): add trigger_info to WorkflowNodeExecutionMetadataKey Mar 19, 2026
@QuantumGhost QuantumGhost marked this pull request as ready for review March 19, 2026 09:42
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 19, 2026
@github-actions
Copy link
Contributor

Pyrefly Diff

No changes detected.

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Mar 19, 2026
@fatelei fatelei merged commit c93289e into langgenius:main Mar 19, 2026
16 checks passed
fatelei pushed a commit that referenced this pull request Mar 19, 2026
)

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invalid key for NodeRunResult.metadata

2 participants