Skip to content

refactor(models): pass session into WorkflowRun accessors and drop dead ones - #42034

Merged
asukaminato0721 merged 4 commits into
langgenius:mainfrom
keith991001:refactor/workflow-run-session-param
Sep 18, 2026
Merged

asukaminato0721 merged 4 commits into
langgenius:mainfrom
keith991001:refactor/workflow-run-session-param

Conversation

@keith991001

Copy link
Copy Markdown
Contributor

Important

  1. Read CONTRIBUTING.md.
  2. Associated issue: rewrite property to accept session: Session as parameter #40372 (claimed in this comment alongside the merged refactor(models): pass session into WorkflowNodeExecutionModel accessors #41968; this covers the remaining workflow.py accessors).

Summary

Part of #40372, follow-up to #41968 — this finishes models/workflow.py: no db.session-backed @property remains in the file.

  • WorkflowRun.created_by_account / created_by_end_user (both marked @deprecated) → converted to methods taking session, matching the WorkflowAppLog / WorkflowNodeExecutionModel pairs in the same file. Their only remaining readers were implicit from_attributes=True reads by the run list / detail response models, now routed through a session-carrying WorkflowRunResponseSource (plus a pagination helper that wraps each run in the page) at the seven console validation sites (app workflow-runs list ×2 / detail, snippets list / detail, rag-pipeline list / detail). Each site reuses db.session() at the boundary. The advanced-chat list keeps working through WorkflowWithMessage's attribute passthrough — the source resolves the accessor on the underlying run while message_id / conversation_id keep proxying.
  • WorkflowRun.message / WorkflowRun.workflow (also @deprecated) → removed: an untruncated sweep across production, serializers, helper-indirected dump_response sites, events, and tests found zero readers.

Tests

  • New test_workflow_run_accessors.py: both accessors against the real sqlite_session fixture (role dispatch + None paths), the detail source resolving through its wrapped session while proxying other attributes, and the pagination helper wrapping every run in a page.
  • test_workflow_run_api.py contract tests adapted: the db.session monkeypatch is now a callable (matching the scoped-session contract the controllers rely on), and the two mocked paginations use object-shaped results matching what the repository layer actually returns.
  • Full tests/unit_tests run: 18661 passed; the only failures are the same pre-existing test_check_no_new_getattr environment failures that 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 9, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 64.34% 64.36% +0.02%
Strict coverage 63.95% 63.97% +0.02%
Typed symbols 46,478 46,512 +34
Untyped symbols 25,917 25,914 -3
Modules 3417 3418 +1

@asukaminato0721 asukaminato0721 self-assigned this Sep 9, 2026
@keith991001
keith991001 force-pushed the refactor/workflow-run-session-param branch from 9e6d4d8 to a255b31 Compare September 14, 2026 02:29
@keith991001

Copy link
Copy Markdown
Contributor Author

Hi @asukaminato0721 — a friendly ping on this one whenever you have a moment. CI is all green and the branch is up to date. Happy to rebase or adjust anything if needed. Thanks for your time! 🙏

Comment thread api/fields/workflow_run_fields.py Resolved
auto-merge was automatically disabled September 14, 2026 03:12

Head branch was pushed to by a user without write access

@keith991001

Copy link
Copy Markdown
Contributor Author

Hi @asukaminato0721 — just a quick note that both review comments have been addressed in 26c3537 (shared _SessionResponseSource base instead of a new __getattr__, and single-session injection in the rag-pipeline endpoints), with replies in the respective threads. CI is green. Whenever you get a chance to take another look — and of course, happy to adjust further! 🙏

…rator

Review feedback: the workflow-run endpoints this PR touched obtained
their session inline with db.session(). Switch the eight read handlers
across workflow_run.py, rag_pipeline_workflow.py and snippet_workflow.py
to @with_session(write=False), which injects a request-scoped session
and owns its lifecycle. Handler unit tests updated to pass the session
explicitly (real sqlite fixture, no Mock sessions).
auto-merge was automatically disabled September 17, 2026 15:24

Head branch was pushed to by a user without write access

@keith991001
keith991001 force-pushed the refactor/workflow-run-session-param branch from 26c3537 to 9247d1d Compare September 17, 2026 15:24
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-09-17 15:26:09.241332351 +0000
+++ /tmp/pyrefly_pr.txt	2026-09-17 15:26:00.721277335 +0000
@@ -434,6 +434,10 @@
   --> providers/vdb/vdb-vikingdb/tests/unit_tests/test_vikingdb_vector.py:76:5
 ERROR Object of class `ModuleType` has no attribute `VikingDBService` [missing-attribute]
   --> providers/vdb/vdb-vikingdb/tests/unit_tests/test_vikingdb_vector.py:77:5
+ERROR Argument `(self: Self@AdvancedChatAppWorkflowRunListApi, session: Session, req_data: WorkflowRunListQuery, request_context: RequestContext, app_model: App) -> dict[str, Any]` is not assignable to parameter with type `(Self@AdvancedChatAppWorkflowRunListApi, WorkflowRunListQuery, ParamSpec(@_)) -> @_` [bad-argument-type]
+   --> controllers/console/app/workflow_run.py:154:5
+ERROR Argument `(self: Self@WorkflowRunListApi, session: Session, req_data: WorkflowRunListQuery, request_context: RequestContext, app_model: App) -> dict[str, Any]` is not assignable to parameter with type `(Self@WorkflowRunListApi, WorkflowRunListQuery, ParamSpec(@_)) -> @_` [bad-argument-type]
+   --> controllers/console/app/workflow_run.py:219:5
 ERROR Object of class `FromClause` has no attribute `metadata` [missing-attribute]
   --> tests/helpers/legacy_model_type_migration.py:64:16
 ERROR Object of class `FromClause` has no attribute `metadata` [missing-attribute]

@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.00000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.40%. Comparing base (ad9a5be) to head (5e163e4).

Files with missing lines Patch % Lines
...ole/datasets/rag_pipeline/rag_pipeline_workflow.py 60.00% 4 Missing ⚠️
...i/controllers/console/snippets/snippet_workflow.py 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #42034      +/-   ##
==========================================
- Coverage   87.40%   87.40%   -0.01%     
==========================================
  Files        5462     5462              
  Lines      315635   315637       +2     
  Branches    63612    63612              
==========================================
+ Hits       275867   275868       +1     
- Misses      34385    34387       +2     
+ Partials     5383     5382       -1     
Flag Coverage Δ
api 87.08% <90.00%> (-0.01%) ⬇️

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.

@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.

ci

…lers

Pyrefly caught a real wiring bug in the previous commit: with @with_session
stacked outside @model_validate, the decorator chain delivered req_data into
the session parameter and vice versa on the two list endpoints. model_validate
prepends the validated payload directly after self on the callable it wraps,
so the session-injecting decorator must sit innermost for the raw signature
(self, session, req_data, ...) to line up. The unwrap-based unit tests bypass
the decorator chain, which is why they could not catch this.
@keith991001

Copy link
Copy Markdown
Contributor Author

ci

thx! I fixed CI. plz check again

@asukaminato0721
asukaminato0721 added this pull request to the merge queue Sep 18, 2026
Merged via the queue into langgenius:main with commit 21d5e4e Sep 18, 2026
49 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