Skip to content

refactor: pass db session from parameter in WorkflowRunService and controllers#38786

Open
saitejabandaru-in wants to merge 1 commit into
langgenius:mainfrom
saitejabandaru-in:refactor/db-session-param
Open

refactor: pass db session from parameter in WorkflowRunService and controllers#38786
saitejabandaru-in wants to merge 1 commit into
langgenius:mainfrom
saitejabandaru-in:refactor/db-session-param

Conversation

@saitejabandaru-in

Copy link
Copy Markdown

Summary

Resolves #37403.

This PR refactors the WorkflowRunService method get_paginate_advanced_chat_workflow_runs to accept an explicit session parameter rather than relying on the implicit global db.session object. This makes the code more traceable, readable, and easier to test without global mock patching.

Changes

  • Updated get_paginate_advanced_chat_workflow_runs method in WorkflowRunService to accept session: Session = None. If not provided, it falls back to db.session for backwards compatibility.
  • Updated the workflow run controller WorkflowRunApi to pass db.session to the service method call.
  • Refactored test_get_paginate_advanced_chat_workflow_runs_should_attach_message_fields_when_message_exists in test_workflow_run_service.py to pass the mock/fake session directly, removing the need to monkeypatch db.session.
  • Kept the other test using the monkeypatch to verify that the fallback/backwards-compatibility path functions as expected.

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. refactor labels Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-07-11 02:53:27.531328399 +0000
+++ /tmp/pyrefly_pr.txt	2026-07-11 02:53:13.950191753 +0000
@@ -1,3 +1,5 @@
+ERROR Argument `scoped_session[flask_sqlalchemy.session.Session]` is not assignable to parameter `session` with type `sqlalchemy.orm.session.Session | None` in function `services.workflow_run_service.WorkflowRunService.get_paginate_advanced_chat_workflow_runs` [bad-argument-type]
+   --> controllers/console/app/workflow_run.py:183:84
 ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `dify_vdb_alibabacloud_mysql.alibabacloud_mysql_vector.AlibabaCloudMySQLVectorFactory.init_vector` [bad-argument-type]
   --> providers/vdb/vdb-alibabacloud-mysql/tests/unit_tests/test_alibabacloud_mysql_factory.py:42:38
 ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `dify_vdb_alibabacloud_mysql.alibabacloud_mysql_vector.AlibabaCloudMySQLVectorFactory.init_vector` [bad-argument-type]
@@ -460,6 +462,10 @@
    --> providers/vdb/vdb-weaviate/tests/unit_tests/test_weaviate_vector.py:891:42
 ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `dify_vdb_weaviate.weaviate_vector.WeaviateVectorFactory.init_vector` [bad-argument-type]
    --> providers/vdb/vdb-weaviate/tests/unit_tests/test_weaviate_vector.py:920:42
+ERROR `scoped_session[flask_sqlalchemy.session.Session]` is not assignable to variable `session` with type `sqlalchemy.orm.session.Session | None` [bad-assignment]
+  --> services/workflow_run_service.py:85:27
+ERROR Object of class `NoneType` has no attribute `scalars` [missing-attribute]
+  --> services/workflow_run_service.py:86:24
 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]
@@ -8113,7 +8119,9 @@
 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:109:18
 ERROR `Literal['2']` is not assignable to TypedDict key `limit` with type `int` [bad-typed-dict-key]
-   --> tests/unit_tests/services/test_workflow_run_service.py:139:103
+   --> tests/unit_tests/services/test_workflow_run_service.py:139:49
+ERROR Argument `SimpleNamespace` is not assignable to parameter `session` with type `Session | None` in function `services.workflow_run_service.WorkflowRunService.get_paginate_advanced_chat_workflow_runs` [bad-argument-type]
+   --> tests/unit_tests/services/test_workflow_run_service.py:139:63
 ERROR Argument `dict[str, dict[str, str | dict[str, str]] | str]` is not assignable to parameter `object` with type `dict[str, dict[str, list[Unknown] | str] | str]` in function `list.append` [bad-argument-type]
    --> tests/unit_tests/services/test_workflow_service.py:185:13
 ERROR `dict[@_, @_]` is not assignable to TypedDict key `data` with type `BaseNodeData` [bad-typed-dict-key]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 52.85% 52.85% +0.00%
Strict coverage 52.36% 52.36% +0.00%
Typed symbols 32,803 32,804 +1
Untyped symbols 29,539 29,539 0
Modules 2988 2988 0

@41tair

41tair commented Jul 11, 2026

Copy link
Copy Markdown
Member

Hi, thanks for your contribution. There are some style check failures. Could you address them?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make db.session pass from parameter.

2 participants