Skip to content

refactor(api): reduce Dify GraphInitParams usage#34825

Merged
laipz8200 merged 2 commits intomainfrom
refactor/remove-graph-init-params-phase-1
Apr 9, 2026
Merged

refactor(api): reduce Dify GraphInitParams usage#34825
laipz8200 merged 2 commits intomainfrom
refactor/remove-graph-init-params-phase-1

Conversation

@laipz8200
Copy link
Copy Markdown
Member

@laipz8200 laipz8200 commented Apr 9, 2026

Summary

Part of #34822.

This starts Phase 1 of the GraphInitParams removal plan on the Dify side while keeping the current graphon API intact.

  • add a Dify-owned explicit graph init context bridge in the workflow node factory
  • route workflow, pipeline, and single-node entry paths through the explicit context
  • remove the remaining direct run_context read-backs in the touched workflow paths

Screenshots

Before After
N/A (backend-only refactor) N/A (backend-only refactor)

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 && pnpm exec vp staged (frontend) to appease the lint gods

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.
@laipz8200 laipz8200 requested a review from QuantumGhost as a code owner April 9, 2026 06:29
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. refactor labels Apr 9, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Pyrefly Diff

base → 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]

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 9, 2026

Pyrefly Diff

base → 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
Copy link
Copy Markdown

codecov Bot commented Apr 9, 2026

Codecov Report

❌ Patch coverage is 91.66667% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.84%. Comparing base (c19a822) to head (a1ca45e).
⚠️ Report is 17 commits behind head on main.

Files with missing lines Patch % Lines
api/core/app/apps/workflow_app_runner.py 57.14% 3 Missing ⚠️
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           
Flag Coverage Δ
api 82.35% <91.66%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@laipz8200 laipz8200 enabled auto-merge April 9, 2026 07:47
@laipz8200 laipz8200 added this pull request to the merge queue Apr 9, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Apr 9, 2026
Merged via the queue into main with commit d1e33ba Apr 9, 2026
32 checks passed
@laipz8200 laipz8200 deleted the refactor/remove-graph-init-params-phase-1 branch April 9, 2026 08:09
HanqingZ pushed a commit to HanqingZ/dify that referenced this pull request Apr 23, 2026
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 refactor size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants