refactor(api): reduce Dify GraphInitParams usage#34825
Merged
Conversation
Introduce a Dify-owned graph init context bridge in the workflow node factory so production workflow entry points stop constructing GraphInitParams directly. Route workflow, pipeline, and single-node entry paths through the explicit context while keeping the current graphon API unchanged for this phase. Also replace the remaining direct run_context read-backs in the touched workflow paths and add focused unit coverage for the bridge.
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-09 06:31:04.770160490 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-09 06:30:55.980128215 +0000
@@ -5972,17 +5972,17 @@
ERROR Argument `object` is not assignable to parameter `node_data_memory` with type `MemoryConfig | None` in function `core.workflow.node_factory.fetch_memory` [bad-argument-type]
--> tests/unit_tests/core/workflow/test_node_factory.py:102:30
ERROR Argument `SimpleNamespace` is not assignable to parameter `graph_init_params` with type `GraphInitParams` in function `core.workflow.node_factory.DifyNodeFactory.__init__` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_factory.py:249:35
+ --> tests/unit_tests/core/workflow/test_node_factory.py:294:35
ERROR `SimpleNamespace` is not assignable to attribute `graph_runtime_state` with type `GraphRuntimeState` [bad-assignment]
- --> tests/unit_tests/core/workflow/test_node_factory.py:312:39
+ --> tests/unit_tests/core/workflow/test_node_factory.py:357:39
ERROR `SimpleNamespace` is not assignable to attribute `_dify_context` with type `DifyRunContext` [bad-assignment]
- --> tests/unit_tests/core/workflow/test_node_factory.py:313:33
+ --> tests/unit_tests/core/workflow/test_node_factory.py:358:33
ERROR `form_repository` may be uninitialized [unbound-name]
- --> tests/unit_tests/core/workflow/test_node_factory.py:452:49
+ --> tests/unit_tests/core/workflow/test_node_factory.py:497:49
ERROR `SimpleNamespace` is not assignable to attribute `_dify_context` with type `DifyRunContext` [bad-assignment]
- --> tests/unit_tests/core/workflow/test_node_factory.py:595:33
+ --> tests/unit_tests/core/workflow/test_node_factory.py:640:33
ERROR `SimpleNamespace` is not assignable to attribute `graph_runtime_state` with type `GraphRuntimeState` [bad-assignment]
- --> tests/unit_tests/core/workflow/test_node_factory.py:596:39
+ --> tests/unit_tests/core/workflow/test_node_factory.py:641:39
ERROR Object of class `ExternalRecipient` has no attribute `reference_id` [missing-attribute]
--> tests/unit_tests/core/workflow/test_node_runtime.py:88:12
ERROR Argument `object` is not assignable to parameter `method` with type `EmailDeliveryMethod | InteractiveSurfaceDeliveryMethod` in function `core.workflow.node_runtime.apply_dify_debug_email_recipient` [bad-argument-type]
|
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-04-09 06:52:08.118814314 +0000
+++ /tmp/pyrefly_pr.txt 2026-04-09 06:51:59.099757907 +0000
@@ -5972,17 +5972,17 @@
ERROR Argument `object` is not assignable to parameter `node_data_memory` with type `MemoryConfig | None` in function `core.workflow.node_factory.fetch_memory` [bad-argument-type]
--> tests/unit_tests/core/workflow/test_node_factory.py:102:30
ERROR Argument `SimpleNamespace` is not assignable to parameter `graph_init_params` with type `GraphInitParams` in function `core.workflow.node_factory.DifyNodeFactory.__init__` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_node_factory.py:249:35
+ --> tests/unit_tests/core/workflow/test_node_factory.py:294:35
ERROR `SimpleNamespace` is not assignable to attribute `graph_runtime_state` with type `GraphRuntimeState` [bad-assignment]
- --> tests/unit_tests/core/workflow/test_node_factory.py:312:39
+ --> tests/unit_tests/core/workflow/test_node_factory.py:357:39
ERROR `SimpleNamespace` is not assignable to attribute `_dify_context` with type `DifyRunContext` [bad-assignment]
- --> tests/unit_tests/core/workflow/test_node_factory.py:313:33
+ --> tests/unit_tests/core/workflow/test_node_factory.py:358:33
ERROR `form_repository` may be uninitialized [unbound-name]
- --> tests/unit_tests/core/workflow/test_node_factory.py:452:49
+ --> tests/unit_tests/core/workflow/test_node_factory.py:497:49
ERROR `SimpleNamespace` is not assignable to attribute `_dify_context` with type `DifyRunContext` [bad-assignment]
- --> tests/unit_tests/core/workflow/test_node_factory.py:595:33
+ --> tests/unit_tests/core/workflow/test_node_factory.py:640:33
ERROR `SimpleNamespace` is not assignable to attribute `graph_runtime_state` with type `GraphRuntimeState` [bad-assignment]
- --> tests/unit_tests/core/workflow/test_node_factory.py:596:39
+ --> tests/unit_tests/core/workflow/test_node_factory.py:641:39
ERROR Object of class `ExternalRecipient` has no attribute `reference_id` [missing-attribute]
--> tests/unit_tests/core/workflow/test_node_runtime.py:88:12
ERROR Argument `object` is not assignable to parameter `method` with type `EmailDeliveryMethod | InteractiveSurfaceDeliveryMethod` in function `core.workflow.node_runtime.apply_dify_debug_email_recipient` [bad-argument-type]
@@ -6026,13 +6026,13 @@
ERROR Argument `SimpleNamespace` is not assignable to parameter `workflow` with type `Workflow` in function `core.workflow.workflow_entry.WorkflowEntry.single_step_run` [bad-argument-type]
--> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:570:30
ERROR Class member `EmptySplitKey.split` overrides parent class `UserString` in an inconsistent manner [bad-override]
- --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:783:17
+ --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:791:17
ERROR Argument `dict[TestMappingUserInputsBranches.test_rejects_invalid_node_variable_key.EmptySplitKey, Sequence[str]]` is not assignable to parameter `variable_mapping` with type `Mapping[str, Sequence[str]]` in function `core.workflow.workflow_entry.WorkflowEntry.mapping_user_inputs_to_variable_pool` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:788:34
+ --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:796:34
ERROR Argument `TestWorkflowEntryTracing.test_traced_node_run_reports_success.FakeNode` is not assignable to parameter `node` with type `Node[Unknown]` in function `core.workflow.workflow_entry.WorkflowEntry._traced_node_run` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:839:73
+ --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:847:73
ERROR Argument `TestWorkflowEntryTracing.test_traced_node_run_reports_errors.FakeNode` is not assignable to parameter `node` with type `Node[Unknown]` in function `core.workflow.workflow_entry.WorkflowEntry._traced_node_run` [bad-argument-type]
- --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:862:68
+ --> tests/unit_tests/core/workflow/test_workflow_entry_helpers.py:870:68
ERROR Missing argument `case` in function `enterprise.telemetry.contracts.TelemetryEnvelope.__init__` [missing-argument]
--> tests/unit_tests/enterprise/telemetry/test_contracts.py:111:30
ERROR Missing argument `tenant_id` in function `enterprise.telemetry.contracts.TelemetryEnvelope.__init__` [missing-argument]
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #34825 +/- ##
=======================================
Coverage 83.84% 83.84%
=======================================
Files 4185 4186 +1
Lines 176988 177001 +13
Branches 35423 35424 +1
=======================================
+ Hits 148396 148414 +18
+ Misses 25705 25700 -5
Partials 2887 2887
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
WH-2099
approved these changes
Apr 9, 2026
HanqingZ
pushed a commit
to HanqingZ/dify
that referenced
this pull request
Apr 23, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of #34822.
This starts Phase 1 of the
GraphInitParamsremoval plan on the Dify side while keeping the currentgraphonAPI intact.run_contextread-backs in the touched workflow pathsScreenshots
Checklist
make lintandmake type-check(backend) andcd web && pnpm exec vp staged(frontend) to appease the lint gods