[PR #31723] refactor(typing): Fixup typing A2 - workflow engine & nodes #33368

Closed
opened 2026-02-21 20:53:09 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/31723

State: closed
Merged: Yes


Context

Part of #31680 (A2 stage: workflow engine & nodes).

What this PR does

Unblocks running ty on the workflow engine/nodes layer by tightening types, improving narrowing, and removing a few cross-layer import/typing issues.

Key changes:

  • Typed workflow node config

    • Introduces core.workflow.entities.graph_config with NodeConfigDict + NodeConfigDictAdapter.
    • Updates workflow graph parsing (core.workflow.graph.graph.Graph) to validate node configs via Pydantic TypeAdapter and use typed indexing.
    • Updates Workflow.get_node_config_by_id() and workflow entry code to use the typed node config.
  • Protocol-friendly dependency injection for HTTP request node

    • Adds thin adapters:
      • core.helper.ssrf_proxy.SSRFProxy implementing HttpClientProtocol
      • core.file.file_manager.FileManager implementing FileManagerProtocol
    • Updates HttpRequestNode / executor and DifyNodeFactory to accept optional injected deps with safe defaults (no behavioral change intended).
  • Type/narrowing cleanups inside workflow code

    • Reduces cast() usage where types are already structurally guaranteed.
    • Improves runtime narrowing (isinstance) and a few small typing fixes in nodes (e.g. LLM prompt content handling, list operator file field extraction, datasource type conversion).
  • Tooling

    • Bumps ty to >=0.0.14 and updates ty.toml rules/excludes for this stage.

Why

The workflow codebase has import-linter enforced layering, including that core.workflow.nodes.* must not import core.workflow.graph.*.

During the A2 work, models/workflow.py importing node-config typing from core.workflow.graph.graph created an indirect dependency chain that broke the rule once graph parsing started depending on node-typed configs.

Moving the shared node-config TypedDict into core.workflow.entities keeps the architecture boundary intact while still allowing Graph/Workflow/factories to share the same validated config shape.

Testing

  • uv run --directory api --dev ty check
  • uv run --directory api --dev lint-imports
**Original Pull Request:** https://github.com/langgenius/dify/pull/31723 **State:** closed **Merged:** Yes --- ## Context Part of #31680 (**A2 stage: workflow engine & nodes**). ## What this PR does Unblocks running `ty` on the workflow engine/nodes layer by tightening types, improving narrowing, and removing a few cross-layer import/typing issues. Key changes: - **Typed workflow node config** - Introduces `core.workflow.entities.graph_config` with `NodeConfigDict` + `NodeConfigDictAdapter`. - Updates workflow graph parsing (`core.workflow.graph.graph.Graph`) to validate node configs via Pydantic `TypeAdapter` and use typed indexing. - Updates `Workflow.get_node_config_by_id()` and workflow entry code to use the typed node config. - **Protocol-friendly dependency injection for HTTP request node** - Adds thin adapters: - `core.helper.ssrf_proxy.SSRFProxy` implementing `HttpClientProtocol` - `core.file.file_manager.FileManager` implementing `FileManagerProtocol` - Updates `HttpRequestNode` / executor and `DifyNodeFactory` to accept optional injected deps with safe defaults (no behavioral change intended). - **Type/narrowing cleanups inside workflow code** - Reduces `cast()` usage where types are already structurally guaranteed. - Improves runtime narrowing (`isinstance`) and a few small typing fixes in nodes (e.g. LLM prompt content handling, list operator file field extraction, datasource type conversion). - **Tooling** - Bumps `ty` to `>=0.0.14` and updates `ty.toml` rules/excludes for this stage. ## Why The workflow codebase has import-linter enforced layering, including that `core.workflow.nodes.*` must not import `core.workflow.graph.*`. During the A2 work, `models/workflow.py` importing node-config typing from `core.workflow.graph.graph` created an indirect dependency chain that broke the rule once graph parsing started depending on node-typed configs. Moving the shared node-config `TypedDict` into `core.workflow.entities` keeps the architecture boundary intact while still allowing `Graph`/`Workflow`/factories to share the same validated config shape. ## Testing - `uv run --directory api --dev ty check` - `uv run --directory api --dev lint-imports`
yindo added the pull-request label 2026-02-21 20:53:09 -05:00
yindo closed this issue 2026-02-21 20:53:09 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#33368