refactor: pass db.session explicitly in 8 services (#37403)#37793
Open
EvanYao826 wants to merge 4 commits into
Open
refactor: pass db.session explicitly in 8 services (#37403)#37793EvanYao826 wants to merge 4 commits into
EvanYao826 wants to merge 4 commits into
Conversation
…#37403) Migrate db.session to explicit session parameter in 8 service files, following the pattern established in langgenius#37402. ### Service files: - clear_free_plan_tenant_expired_logs.py - knowledge_retrieval_inner_service.py - account_service.py - credit_pool_service.py - hit_testing_service.py - webapp_auth_service.py - workspace_service.py - agent/skill_tool_inference_service.py ### Controllers: - console/app/agent.py - console/datasets/external.py - console/datasets/hit_testing_base.py - console/workspace/workspace.py - inner_api/knowledge/retrieval.py ### Tests: - services/agent/test_skill_tool_inference_service.py Closes langgenius#37403 (partial)
asukaminato0721
previously approved these changes
Jun 23, 2026
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-06-24 06:04:09.880950948 +0000
+++ /tmp/pyrefly_pr.txt 2026-06-24 06:03:55.163762163 +0000
@@ -1,3 +1,7 @@
+ERROR Parse error: Duplicate keyword argument "session" [parse-error]
+ --> controllers/console/datasets/external.py:400:17
+ERROR Multiple values for argument `session` in function `services.hit_testing_service.HitTestingService.external_retrieve` [bad-keyword-argument]
+ --> controllers/console/datasets/external.py:400:17
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 +464,14 @@
--> providers/vdb/vdb-weaviate/tests/unit_tests/test_weaviate_vector.py:887: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:916:42
+ERROR Duplicate parameter "session" [invalid-syntax]
+ --> services/hit_testing_service.py:118:9
+ERROR Duplicate parameter "session" [invalid-syntax]
+ --> services/hit_testing_service.py:203:9
+ERROR Could not find name `db` [unknown-name]
+ --> services/webapp_auth_service.py:38:74
+ERROR Could not find name `db` [unknown-name]
+ --> services/webapp_auth_service.py:58:74
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]
@@ -1146,6 +1158,8 @@
--> tests/test_containers_integration_tests/services/test_app_service.py:1571:41
ERROR Argument `Literal['owner']` is not assignable to parameter `role` with type `SQLCoreOperations[TenantAccountRole] | TenantAccountRole` in function `models.account.TenantAccountJoin.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/services/test_conversation_service_variables.py:47:18
+ERROR Missing argument `session` in function `services.credit_pool_service.CreditPoolService.create_default_pool` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_credit_pool_service.py:42:53
ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/services/test_dataset_permission_service.py:39:20
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -1394,8 +1408,14 @@
--> tests/test_containers_integration_tests/services/test_webapp_auth_service.py:142:20
ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/services/test_webapp_auth_service.py:345:20
+ERROR Missing argument `session` in function `services.webapp_auth_service.WebAppAuthService.create_end_user` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_webapp_auth_service.py:662:51
+ERROR Missing argument `session` in function `services.webapp_auth_service.WebAppAuthService.create_end_user` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_webapp_auth_service.py:697:46
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/services/test_webapp_auth_service.py:715:20
+ERROR Missing argument `session` in function `services.webapp_auth_service.WebAppAuthService.create_end_user` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_webapp_auth_service.py:735:46
ERROR Argument `dict[str, dict[str, list[dict[str, bool | str]] | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
--> tests/test_containers_integration_tests/services/test_webhook_service.py:289:88
ERROR Argument `dict[str, dict[str, str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.extract_and_validate_webhook_data` [bad-argument-type]
@@ -1472,20 +1492,32 @@
--> tests/test_containers_integration_tests/services/test_workspace_service.py:53:20
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:62:20
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:107:54
ERROR Cannot index into `object` [bad-index]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:121:20
ERROR `in` is not supported between `Literal['replace_webapp_logo']` and `object` [not-iterable]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:122:20
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:154:54
ERROR Object of class `NoneType` has no attribute `role` [missing-attribute]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:199:9
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:209:54
ERROR Object of class `NoneType` has no attribute `role` [missing-attribute]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:253:9
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:264:54
ERROR Cannot index into `object` [bad-index]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:272:20
ERROR `in` is not supported between `Literal['replace_webapp_logo']` and `object` [not-iterable]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:273:20
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:294:50
ERROR Argument `None` is not assignable to parameter `tenant` with type `Tenant` in function `services.workspace_service.WorkspaceService.get_tenant_info` [bad-argument-type]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:294:51
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:344:58
ERROR `in` is not supported between `Literal['replace_webapp_logo']` and `object` [not-iterable]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:351:28
ERROR Cannot index into `object` [bad-index]
@@ -1496,8 +1528,14 @@
--> tests/test_containers_integration_tests/services/test_workspace_service.py:358:24
ERROR Object of class `NoneType` has no attribute `role` [missing-attribute]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:389:9
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:401:54
ERROR Object of class `NoneType` has no attribute `role` [missing-attribute]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:439:9
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:451:54
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:516:58
ERROR `in` is not supported between `Literal['replace_webapp_logo']` and `object` [not-iterable]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:524:28
ERROR Cannot index into `object` [bad-index]
@@ -1512,10 +1550,32 @@
--> tests/test_containers_integration_tests/services/test_workspace_service.py:545:100
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:549:53
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:556:49
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:575:54
ERROR Cannot index into `object` [bad-index]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:578:16
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:599:54
ERROR Cannot index into `object` [bad-index]
--> tests/test_containers_integration_tests/services/test_workspace_service.py:602:16
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:618:54
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:645:54
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:672:54
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:700:54
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:729:54
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:757:54
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:788:54
+ERROR Missing argument `session` in function `services.workspace_service.WorkspaceService.get_tenant_info` [missing-argument]
+ --> tests/test_containers_integration_tests/services/test_workspace_service.py:814:54
ERROR Argument `Literal['active']` is not assignable to parameter `status` with type `AccountStatus | SQLCoreOperations[AccountStatus]` in function `models.account.Account.__init__` [bad-argument-type]
--> tests/test_containers_integration_tests/services/tools/test_api_tools_manage_service.py:60:20
ERROR Argument `Literal['normal']` is not assignable to parameter `status` with type `SQLCoreOperations[TenantStatus] | TenantStatus` in function `models.account.Tenant.__init__` [bad-argument-type]
@@ -6872,6 +6932,8 @@
--> tests/unit_tests/services/test_clear_free_plan_expired_workflow_run_logs.py:126:49
ERROR Class member `FailingRepo.delete_runs_with_related_by_ids` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
--> tests/unit_tests/services/test_clear_free_plan_expired_workflow_run_logs.py:394:13
+ERROR Missing argument `session` in function `services.clear_free_plan_tenant_expired_logs.ClearFreePlanTenantExpiredLogs.process_tenant` [missing-argument]
+ --> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:328:50
ERROR Class member `FixedDateTime.now` overrides parent class `datetime` in an inconsistent manner [bad-override]
--> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:403:13
ERROR Class member `FixedDateTime.now` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
@@ -6880,6 +6942,8 @@
--> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:478:13
ERROR Class member `FixedDateTime.now` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
--> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:478:13
+ERROR Missing argument `session` in function `services.clear_free_plan_tenant_expired_logs.ClearFreePlanTenantExpiredLogs.process_tenant` [missing-argument]
+ --> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:586:50
ERROR Argument `SimpleNamespace` is not assignable to parameter `user` with type `Account` in function `services.credential_permission_service.CredentialPermissionService.apply_visibility_filter` [bad-argument-type]
--> tests/unit_tests/services/test_credential_permission_service.py:80:18
ERROR Argument `SimpleNamespace` is not assignable to parameter `user` with type `Account` in function `services.credential_permission_service.CredentialPermissionService.apply_visibility_filter` [bad-argument-type]
|
Contributor
Pyrefly Type Coverage
|
Contributor
|
fix ci |
Contributor
Author
|
Checking issue-level comments... |
Contributor
Author
|
Hi @asukaminato0721, thanks for the review! I noticed you left an empty suggestion on |
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
Migrate
db.sessionusage to explicitsessionparameter in 8 service files, following the pattern established in #37402.Service files changed:
api/services/clear_free_plan_tenant_expired_logs.pyapi/services/knowledge_retrieval_inner_service.pyapi/services/account_service.pyapi/services/credit_pool_service.pyapi/services/hit_testing_service.pyapi/services/webapp_auth_service.pyapi/services/workspace_service.pyapi/services/agent/skill_tool_inference_service.pyControllers updated:
api/controllers/console/app/agent.pyapi/controllers/console/datasets/external.pyapi/controllers/console/datasets/hit_testing_base.pyapi/controllers/console/workspace/workspace.pyapi/controllers/inner_api/knowledge/retrieval.pyTests updated:
api/tests/unit_tests/services/agent/test_skill_tool_inference_service.pyPattern
All callers (controllers) updated to pass
db.sessionexplicitly.Part of #37403 (incremental; not using
Fixessince the umbrella issue spans many services).