Skip to content

refactor(models): pass session into WorkflowNodeExecutionModel accessors - #41968

Merged
asukaminato0721 merged 1 commit into
langgenius:mainfrom
keith991001:refactor/workflow-node-execution-session-param
Sep 8, 2026
Merged

asukaminato0721 merged 1 commit into
langgenius:mainfrom
keith991001:refactor/workflow-node-execution-session-param

Conversation

@keith991001

Copy link
Copy Markdown
Contributor

Summary

Part of #40372, follow-up to #41440 / #41911. This is the deep-water pair deliberately skipped in earlier slices.

Converts WorkflowNodeExecutionModel.created_by_account / created_by_end_user from @property accessors reaching for the global db.session into methods taking session explicitly, matching the already-merged WorkflowAppLog pair in the same file. Because these two were read both implicitly and explicitly, the PR routes every consumer through an explicit session:

  • Response validation (implicit, from_attributes=True): added a session-carrying WorkflowNodeExecutionResponseSource in fields/workflow_run_fields.py (the SegmentWithSummary / DatasetDetailResponseSource pattern) and routed the seven WorkflowRunNodeExecutionResponse.model_validate(...) sites across the console app / snippets / rag-pipeline controllers through it, each reusing the session the endpoint already touches.
  • Trace assembly (explicit): assemble_workflow_node_execution_traces and its _retry_trace / _terminal_trace helpers now take session; the three service callers pass it from their own infrastructure (SnippetService._session_scope(), RagPipelineService._session, and db.session() at the repository-only WorkflowRunService boundary).

Tests

  • New test_workflow_node_execution_accessors.py: both accessors exercised against the real sqlite_session fixture (role-based dispatch + None paths), plus the response source resolving through its wrapped session while proxying other attributes.
  • Existing suites adapted: the trace-service tests now pass the session explicitly (their db monkeypatch no longer carries the accessors), mock assertions in the snippet / workflow-run / rag-pipeline service tests include the new kwarg, the two controller contract tests wrap their raw ORM fixtures in the response source, and the container-integration tests call the methods with the test session.
  • tests/unit_tests full run: 18680 passed; the only failures are the pre-existing test_check_no_new_getattr environment failures, which fail identically on a clean main checkout on this machine.

Screenshots

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 && make type-check (backend) and vp staged (frontend) to appease the lint gods

From Claude Code

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-09-08 07:47:18.539855963 +0000
+++ /tmp/pyrefly_pr.txt	2026-09-08 07:47:08.930820776 +0000
@@ -3375,7 +3375,7 @@
 ERROR Argument `str | None` is not assignable to parameter `s` with type `bytearray | bytes | str` in function `json.loads` [bad-argument-type]
    --> tests/unit_tests/controllers/console/app/test_model_config_api.py:256:36
 ERROR Object of class `WorkflowRun` has no attribute `retry_index` [missing-attribute]
-   --> tests/unit_tests/controllers/console/app/test_workflow_run_api.py:109:5
+   --> tests/unit_tests/controllers/console/app/test_workflow_run_api.py:110:5
 ERROR Missing argument `app_model` in function `handler` [missing-argument]
   --> tests/unit_tests/controllers/console/app/test_wraps.py:45:19
 ERROR Unexpected keyword argument `app_id` in function `handler` [unexpected-keyword]
@@ -8337,23 +8337,23 @@
 ERROR Class member `DummyRetrieval.get_type` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
   --> tests/unit_tests/services/rag_pipeline/pipeline_template/test_pipeline_template_base.py:16:9
 ERROR Argument `tuple[str, ...]` is not assignable to parameter `key` with type `tuple[str, str]` in function `dict.get` [bad-argument-type]
-   --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:205:37
+   --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:206:37
 ERROR Object of class `NoneType` has no attribute `marked_name` [missing-attribute]
-   --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:489:12
-ERROR Object of class `NoneType` has no attribute `marked_comment` [missing-attribute]
    --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:490:12
+ERROR Object of class `NoneType` has no attribute `marked_comment` [missing-attribute]
+   --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:491:12
 ERROR Object of class `NoneType` has no attribute `updated_by` [missing-attribute]
-   --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:492:12
+   --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:493:12
 ERROR Argument `dict[str, list[dict[str, dict[str, str | dict[str, str] | dict[str, int | str]]]]]` is not assignable to parameter `graph` with type `dict[str, object] | None` in function `_make_workflow` [bad-argument-type]
-   --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:608:67
+   --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:609:67
 ERROR Argument `() -> tuple[SimpleNamespace, Generator[NodeRunFailedEvent, Unknown]]` is not assignable to parameter `getter` with type `() -> tuple[Node[Unknown], Generator[GraphNodeEventBase | IterationFrameRequest | LoopFrameRequest]]` in function `services.rag_pipeline.rag_pipeline.RagPipelineService._handle_node_run_result` [bad-argument-type]
-    --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:1410:16
+    --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:1411:16
 ERROR Argument `() -> tuple[SimpleNamespace, Generator[object, Unknown]]` is not assignable to parameter `getter` with type `() -> tuple[Node[Unknown], Generator[GraphNodeEventBase | IterationFrameRequest | LoopFrameRequest]]` in function `services.rag_pipeline.rag_pipeline.RagPipelineService._handle_node_run_result` [bad-argument-type]
-    --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:1792:20
+    --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:1793:20
 ERROR Argument `() -> tuple[SimpleNamespace, Iterator[Any]]` is not assignable to parameter `getter` with type `() -> tuple[Node[Unknown], Generator[GraphNodeEventBase | IterationFrameRequest | LoopFrameRequest]]` in function `services.rag_pipeline.rag_pipeline.RagPipelineService._handle_node_run_result` [bad-argument-type]
-    --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:1812:16
+    --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:1813:16
 ERROR Argument `() -> tuple[SimpleNamespace, Iterator[Any]]` is not assignable to parameter `getter` with type `() -> tuple[Node[Unknown], Generator[GraphNodeEventBase | IterationFrameRequest | LoopFrameRequest]]` in function `services.rag_pipeline.rag_pipeline.RagPipelineService._handle_node_run_result` [bad-argument-type]
-    --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:1832:16
+    --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_service.py:1833:16
 ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[str, object]) [no-matching-overload]
   --> tests/unit_tests/services/rag_pipeline/test_rag_pipeline_transform_service.py:29:18
 ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[str, object]) [no-matching-overload]
@@ -8643,15 +8643,15 @@
 ERROR `SimpleNamespace` is not assignable to attribute `_node_execution_service_repo` with type `DifyAPIWorkflowNodeExecutionRepository` [bad-assignment]
    --> tests/unit_tests/services/test_snippet_service.py:970:44
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_service.py:977:12
+   --> tests/unit_tests/services/test_snippet_service.py:979:12
 ERROR Object of class `NoneType` has no attribute `id` [missing-attribute]
-   --> tests/unit_tests/services/test_snippet_service.py:980:9
+   --> tests/unit_tests/services/test_snippet_service.py:982:9
 ERROR `SimpleNamespace` is not assignable to attribute `_node_execution_service_repo` with type `DifyAPIWorkflowNodeExecutionRepository` [bad-assignment]
-    --> tests/unit_tests/services/test_snippet_service.py:1013:44
+    --> tests/unit_tests/services/test_snippet_service.py:1015:44
 ERROR Object of class `FunctionType` has no attribute `assert_not_called` [missing-attribute]
-    --> tests/unit_tests/services/test_snippet_service.py:1022:5
+    --> tests/unit_tests/services/test_snippet_service.py:1024:5
 ERROR Object of class `NoneType` has no attribute `use_count` [missing-attribute]
-    --> tests/unit_tests/services/test_snippet_service.py:1035:12
+    --> tests/unit_tests/services/test_snippet_service.py:1037:12
 ERROR Could not find name `PendingRollbackError` [unknown-name]
    --> tests/unit_tests/services/test_summary_index_service.py:432:19
 ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
@@ -8731,21 +8731,21 @@
 ERROR Argument `dict[str, str]` is not assignable to parameter `full_process_data` with type `dict[str, object] | None` in function `_repository` [bad-argument-type]
    --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:111:79
 ERROR Argument `dict[str, list[dict[str, int] | dict[str, object]]]` is not assignable to parameter `process_data` with type `dict[str, object]` in function `_execution` [bad-argument-type]
-   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:128:66
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:129:21
 ERROR Argument `dict[str, list[dict[str, int] | dict[str, object]]]` is not assignable to parameter `full_process_data` with type `dict[str, object] | None` in function `_repository` [bad-argument-type]
-   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:128:94
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:129:49
 ERROR Argument `dict[str, list[dict[str, object]]]` is not assignable to parameter `process_data` with type `dict[str, object]` in function `_execution` [bad-argument-type]
-   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:137:66
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:140:21
 ERROR Argument `dict[str, list[dict[str, object]]]` is not assignable to parameter `full_process_data` with type `dict[str, object] | None` in function `_repository` [bad-argument-type]
-   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:137:94
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:140:49
 ERROR Argument `dict[str, list[dict[str, object]]]` is not assignable to parameter `process_data` with type `dict[str, object]` in function `_execution` [bad-argument-type]
-   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:145:28
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:149:28
 ERROR Object of class `FunctionType` has no attribute `side_effect` [missing-attribute]
-   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:147:5
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:151:5
 ERROR Argument `dict[str, list[dict[str, object]]]` is not assignable to parameter `process_data` with type `dict[str, object]` in function `_execution` [bad-argument-type]
-   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:156:66
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:161:21
 ERROR Argument `dict[str, list[dict[str, object]]]` is not assignable to parameter `full_process_data` with type `dict[str, object] | None` in function `_repository` [bad-argument-type]
-   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:156:94
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:161:49
 ERROR Argument `dict[str, str]` is not assignable to parameter `args` with type `WorkflowRunListArgs` in function `services.workflow_run_service.WorkflowRunService.get_paginate_workflow_runs` [bad-argument-type]
   --> tests/unit_tests/services/test_workflow_run_service.py:83:18
 ERROR `Literal['2']` is not assignable to TypedDict key `limit` with type `int` [bad-assignment]

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 63.80% 63.81% +0.01%
Strict coverage 63.41% 63.42% +0.01%
Typed symbols 45,485 45,507 +22
Untyped symbols 25,969 25,968 -1
Modules 3382 3383 +1

@asukaminato0721 asukaminato0721 self-assigned this Sep 8, 2026
@asukaminato0721
asukaminato0721 added this pull request to the merge queue Sep 8, 2026
Merged via the queue into langgenius:main with commit f3e5f41 Sep 8, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants