Skip to content

refactor(models): pass session into WorkflowDraftVariable value decoding - #43112

Merged
asukaminato0721 merged 8 commits into
langgenius:mainfrom
keith991001:refactor/workflow-draft-variable-session
Nov 12, 2026
Merged

asukaminato0721 merged 8 commits into
langgenius:mainfrom
keith991001:refactor/workflow-draft-variable-session

Conversation

@keith991001

@keith991001 keith991001 commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Part of #40372 (claimed in #40372 (comment)). This removes the global db.session lookup from draft-variable value decoding in api/models/workflow.py.

The decoding chain now takes an explicit Session. WorkflowDraftVariableService uses its caller's session, and DraftVarLoader decodes variables while the loading session remains open. Offloaded values loaded by worker threads use separate short-lived sessions.

Response serialization uses WorkflowDraftVariableResponseSource, based on SessionResponseSource. The app, RAG pipeline, and snippet controllers pass their active sessions at the response boundary. Value-bearing responses reject bare models to prevent leaking serialized JSON as the value. File URL refresh and the cached-value copy behavior from current main are preserved.

Rebased on current main on 2026-11-11, adapting tests to the consolidated model, service, and field test files. Handler tests exercise real services against SQLite. Follow-up c05590d also removes obsolete test patches of the deleted model-level database binding and adds required return annotations. The explicit session injection requested in review is retained.

Current validation: 298 related unit tests passed; Ruff formatting/lint passed for all 18 changed Python files; Pyrefly reported 0 diagnostics for the six changed production files; the no-new-test-doubles guard and git diff --check passed. On c05590d, GitHub Main CI Pipeline #61563 passed, including both unit shards, controllers, integration tests, Python Style and Web E2E. Codecov patch coverage remained at 89.91% against a 90.13% target after all reports arrived. Follow-up e998b3e adds SQLite-backed snippet GET/PATCH tests for decoded response values and persisted updates; its 15-test suite, Ruff and strict Pyrefly check pass locally. GitHub Main CI Pipeline #61569 passed on e998b3e. Final Codecov patch coverage is 91.59% (target 90.13%) and the API project coverage check passed at 90.01%. All 39 current checks passed, with 14 skipped and none failing.

Originally assisted by Claude Code; current rebase and test updates assisted by Codex (GPT-6).


Drafted-by: Codex (GPT-6); reviewed by @keith991001 before posting

@github-actions github-actions Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Sep 29, 2026
@ghfind-review ghfind-review Bot added the review: medium ghfind author score; see https://ghfind.com label Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-11-12 01:44:19.105652642 +0000
+++ /tmp/pyrefly_pr.txt	2026-11-12 01:43:58.725479404 +0000
@@ -5878,55 +5878,55 @@
 ERROR Argument `None` is not assignable to parameter `value` with type `SQLCoreOperations[UploadFile] | UploadFile` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
    --> tests/unit_tests/services/test_workflow_draft_variable_service.py:203:41
 ERROR Argument `Literal['opendal']` is not assignable to parameter `storage_type` with type `StorageType` in function `models.model.UploadFile.__init__` [bad-argument-type]
-   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:235:30
+   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:299:30
 ERROR Argument `Literal['account']` is not assignable to parameter `created_by_role` with type `CreatorUserRole` in function `models.model.UploadFile.__init__` [bad-argument-type]
-   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:241:33
+   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:305:33
 ERROR Argument `Literal['opendal']` is not assignable to parameter `storage_type` with type `StorageType` in function `models.model.UploadFile.__init__` [bad-argument-type]
-   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:291:30
+   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:355:30
 ERROR Argument `Literal['account']` is not assignable to parameter `created_by_role` with type `CreatorUserRole` in function `models.model.UploadFile.__init__` [bad-argument-type]
-   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:297:33
+   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:361:33
 ERROR Object of class `Account` has no attribute `tenant_id` [missing-attribute]
-   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:740:13
+   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:804:13
 ERROR Object of class `Account` has no attribute `tenant_id` [missing-attribute]
-   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:775:13
+   --> tests/unit_tests/services/test_workflow_draft_variable_service.py:839:13
 ERROR Argument `None` is not assignable to parameter `value` with type `SQLCoreOperations[bool] | bool` in function `sqlalchemy.orm.base.Mapped.__set__` [bad-argument-type]
-    --> tests/unit_tests/services/test_workflow_draft_variable_service.py:1168:41
+    --> tests/unit_tests/services/test_workflow_draft_variable_service.py:1232:41
 ERROR Argument `Literal['workflow-run']` is not assignable to parameter `triggered_from` with type `SQLCoreOperations[WorkflowNodeExecutionTriggeredFrom] | WorkflowNodeExecutionTriggeredFrom` in function `models.workflow.WorkflowNodeExecutionModel.__init__` [bad-argument-type]
-    --> tests/unit_tests/services/test_workflow_draft_variable_service.py:1754:32
+    --> tests/unit_tests/services/test_workflow_draft_variable_service.py:1818:32
 ERROR No matching overload found for function `typing.MutableMapping.update` called with arguments: (dict[str, object]) [no-matching-overload]
-  --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:41:18
+  --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:32:18
 ERROR Argument `dict[str, list[dict[str, object]] | str]` 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:86:28
+  --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:77:28
 ERROR Argument `dict[str, list[dict[str, object]] | 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:87:30
+  --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:78:30
 ERROR `not in` is not supported between `Literal['__dify_retry_history']` and `None` [not-iterable]
-  --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:96:12
+  --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:87:12
 ERROR Object of class `FunctionType` has no attribute `assert_called_once_with` [missing-attribute]
-   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:105:5
+  --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:96:5
 ERROR Argument `dict[str, str]` 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:110:28
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:101:28
 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:112:79
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:103: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:130:21
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:121: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:130:49
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:121: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:141:21
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:132: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:141:49
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:132: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:150:28
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:141:28
 ERROR Object of class `FunctionType` has no attribute `side_effect` [missing-attribute]
-   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:152:5
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:143: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:162:21
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:153: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:162:49
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:153: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:182:25
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:173:25
 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:182:53
+   --> tests/unit_tests/services/test_workflow_node_execution_trace_service.py:173:53
 ERROR Missing argument `user_from` in function `core.app.entities.app_invoke_entities.WorkflowAppGenerateEntity.model_construct` [missing-argument]
    --> tests/unit_tests/services/test_workflow_persistence.py:327:76
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_config` with type `WorkflowUIBasedAppConfig` in function `core.app.entities.app_invoke_entities.WorkflowAppGenerateEntity.model_construct` [bad-argument-type]

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 85.19% 85.20% +0.01%
Strict coverage 84.86% 84.87% +0.01%
Typed symbols 90,186 90,278 +92
Untyped symbols 15,738 15,739 +1
Modules 4475 4477 +2

@codecov

codecov Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.07563% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.15%. Comparing base (a75c498) to head (7772dfc).
⚠️ Report is 33 commits behind head on main.

Files with missing lines Patch % Lines
...tasets/rag_pipeline/rag_pipeline_draft_variable.py 81.81% 4 Missing and 2 partials ⚠️
...controllers/console/app/workflow_draft_variable.py 91.89% 2 Missing and 1 partial ⚠️
api/models/workflow.py 76.92% 3 Missing ⚠️
...onsole/snippets/snippet_workflow_draft_variable.py 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #43112      +/-   ##
==========================================
+ Coverage   90.13%   90.15%   +0.01%     
==========================================
  Files        6305     6307       +2     
  Lines      394701   394738      +37     
  Branches    79183    79183              
==========================================
+ Hits       355779   355871      +92     
+ Misses      32806    32755      -51     
+ Partials     6116     6112       -4     
Flag Coverage Δ
api 90.01% <89.07%> (+0.02%) ⬆️

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

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added size:XXL This PR changes 1000+ lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Sep 29, 2026

@asukaminato0721 asukaminato0721 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rebase

@asukaminato0721 asukaminato0721 self-assigned this Nov 10, 2026
auto-merge was automatically disabled November 11, 2026 08:54

Head branch was pushed to by a user without write access

@keith991001
keith991001 force-pushed the refactor/workflow-draft-variable-session branch from be406c2 to 672e959 Compare November 11, 2026 08:54
@keith991001

keith991001 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Rebased on current main as requested. The explicit session injection is retained, tests follow the consolidated upstream layout, and serialization preserves the current file URL refresh/copy behavior. The first CI run found missing test return annotations and obsolete fixture patches of models.workflow.db; these are fixed in c05590d.

Validation: 296 related unit tests passed, including the three suites affected by the CI failures. Ruff formatting/lint passed for all 17 changed Python files; Pyrefly reported 0 diagnostics for the six changed production files and the four strict field/model/handler test files. GitHub CI is rerunning on the updated head.


Drafted-by: Codex (GPT-6); reviewed by @keith991001 before posting

@keith991001

keith991001 commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor Author

Resolved the remaining coverage failure in e998b3e by adding SQLite-backed snippet variable GET/PATCH tests that verify decoded response values and persisted updates.

Main CI Pipeline #61569 passed, including unit, controller, integration, style/type and Web E2E checks. After all coverage reports arrived, Codecov patch coverage passed at 91.59% (target 90.13%), and API project coverage passed at 90.01%. Current head has 39 successful checks, 14 skipped, and no failures.


Drafted-by: Codex (GPT-6); reviewed by @keith991001 before posting

auto-merge was automatically disabled November 12, 2026 01:42

Head branch was pushed to by a user without write access

@asukaminato0721
asukaminato0721 added this pull request to the merge queue Nov 12, 2026
Merged via the queue into langgenius:main with commit 4e1c01b Nov 12, 2026
50 of 51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review: medium ghfind author score; see https://ghfind.com size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants