Skip to content

refactor: pass db session into service calls (#37403)#38016

Merged
asukaminato0721 merged 3 commits into
langgenius:mainfrom
xiejl001:refactor/pass-db-session-into-selected-service-calls
Jun 26, 2026
Merged

refactor: pass db session into service calls (#37403)#38016
asukaminato0721 merged 3 commits into
langgenius:mainfrom
xiejl001:refactor/pass-db-session-into-selected-service-calls

Conversation

@xiejl001

Copy link
Copy Markdown
Contributor

Summary

Pass explicit database sessions into selected service calls.

Refs #37403

Changes

  • Passed active database sessions through billing controller and billing service calls.
  • Passed database sessions through workspace model provider and credential permission service flows.
  • Updated tenant cleanup and builtin tool management service calls to use explicit session boundaries.
  • Updated affected unit and test-container tests for the new service call signatures.

Why

Passing the database session explicitly keeps related operations within the intended transaction/session boundary and makes service dependencies clearer in tests and call sites.

Screenshots

N/A, backend refactor only.

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 cd web && pnpm exec vp staged (frontend) to appease the lint gods

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. refactor labels Jun 26, 2026
@github-actions

github-actions Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-06-26 07:40:13.108983518 +0000
+++ /tmp/pyrefly_pr.txt	2026-06-26 07:39:58.091890135 +0000
@@ -6873,29 +6873,29 @@
 ERROR Argument `SimpleNamespace` is not assignable to parameter `user` with type `Account | EndUser` in function `services.async_workflow_service.AsyncWorkflowService.reinvoke_trigger` [bad-argument-type]
    --> tests/unit_tests/services/test_async_workflow_service.py:322:22
 ERROR Argument `BillingInfo` is not assignable to parameter `result` with type `dict[Unknown, Unknown]` in function `TestBillingServiceSubscriptionInfoDataType._assert_billing_info_types` [bad-argument-type]
-    --> tests/unit_tests/services/test_billing_service.py:1853:41
+    --> tests/unit_tests/services/test_billing_service.py:1856:41
 ERROR Argument `BillingInfo` is not assignable to parameter `result` with type `dict[Unknown, Unknown]` in function `TestBillingServiceSubscriptionInfoDataType._assert_billing_info_types` [bad-argument-type]
-    --> tests/unit_tests/services/test_billing_service.py:1862:41
+    --> tests/unit_tests/services/test_billing_service.py:1865:41
 ERROR Argument `BillingInfo` is not assignable to parameter `result` with type `dict[Unknown, Unknown]` in function `TestBillingServiceSubscriptionInfoDataType._assert_billing_info_types` [bad-argument-type]
-    --> tests/unit_tests/services/test_billing_service.py:1875:41
+    --> tests/unit_tests/services/test_billing_service.py:1878:41
 ERROR Argument `BillingInfo` is not assignable to parameter `result` with type `dict[Unknown, Unknown]` in function `TestBillingServiceSubscriptionInfoDataType._assert_billing_info_types` [bad-argument-type]
-    --> tests/unit_tests/services/test_billing_service.py:1886:41
+    --> tests/unit_tests/services/test_billing_service.py:1889:41
 ERROR Argument `FakeRepo` is not assignable to parameter `workflow_run_repo` with type `APIWorkflowRunRepository | None` in function `services.retention.workflow_run.clear_free_plan_expired_workflow_run_logs.WorkflowRunCleanup.__init__` [bad-argument-type]
    --> 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 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:405:13
+   --> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:401: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:405:13
+   --> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:401:13
 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:480:13
+   --> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:483: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:480:13
+   --> tests/unit_tests/services/test_clear_free_plan_tenant_expired_logs.py:483:13
 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
+  --> tests/unit_tests/services/test_credential_permission_service.py:82: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]
-  --> tests/unit_tests/services/test_credential_permission_service.py:97:18
+  --> tests/unit_tests/services/test_credential_permission_service.py:99:18
 ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
   --> tests/unit_tests/services/test_credit_pool_service.py:24:5
 ERROR Object of class `FromClause` has no attribute `insert` [missing-attribute]

@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 51.34% 51.35% +0.00%
Strict coverage 50.86% 50.86% +0.00%
Typed symbols 30,576 30,579 +3
Untyped symbols 29,254 29,254 0
Modules 2929 2929 0

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels Jun 26, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 26, 2026
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Jun 26, 2026
Merged via the queue into langgenius:main with commit 3f2ef24 Jun 26, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer refactor size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants