refactor: pass db session from parameter in WorkflowRunService and controllers#38786
Open
saitejabandaru-in wants to merge 1 commit into
Open
refactor: pass db session from parameter in WorkflowRunService and controllers#38786saitejabandaru-in wants to merge 1 commit into
saitejabandaru-in wants to merge 1 commit into
Conversation
Contributor
Pyrefly Diffbase → 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]
|
Contributor
Pyrefly Type Coverage
|
Member
|
Hi, thanks for your contribution. There are some style check failures. Could you address them? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #37403.
This PR refactors the
WorkflowRunServicemethodget_paginate_advanced_chat_workflow_runsto accept an explicitsessionparameter rather than relying on the implicit globaldb.sessionobject. This makes the code more traceable, readable, and easier to test without global mock patching.Changes
get_paginate_advanced_chat_workflow_runsmethod inWorkflowRunServiceto acceptsession: Session = None. If not provided, it falls back todb.sessionfor backwards compatibility.WorkflowRunApito passdb.sessionto the service method call.test_get_paginate_advanced_chat_workflow_runs_should_attach_message_fields_when_message_existsintest_workflow_run_service.pyto pass the mock/fake session directly, removing the need to monkeypatchdb.session.