Skip to content

chore: dep inject for session - #35934

Merged
asukaminato0721 merged 3 commits into
langgenius:mainfrom
asukaminato0721:24138
May 8, 2026
Merged

asukaminato0721 merged 3 commits into
langgenius:mainfrom
asukaminato0721:24138

Conversation

@asukaminato0721

@asukaminato0721 asukaminato0721 commented May 8, 2026 •

Copy link
Copy Markdown
Contributor

Important

  1. Make sure you have read our contribution guidelines
  2. Ensure there is an associated issue and you have been assigned to it
  3. Use the correct syntax to link this PR: Fixes #<issue number>.

Summary

let's do this style: for http endpoint, we create a with session.

for any sub call, we do dep injection so no more nest session.

#24138

Screenshots

Before After
... ...

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

@asukaminato0721
asukaminato0721 marked this pull request as ready for review May 8, 2026 10:35
Copilot AI review requested due to automatic review settings May 8, 2026 10:35
@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. refactor labels May 8, 2026
@asukaminato0721
asukaminato0721 enabled auto-merge May 8, 2026 10:35
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-05-08 10:35:51.868764822 +0000
+++ /tmp/pyrefly_pr.txt	2026-05-08 10:35:39.119713651 +0000
@@ -3,9 +3,9 @@
 ERROR `str` is not assignable to `Literal['aliyun-oss', 'azure-blob', 'baidu-obs', 'clickzetta-volume', 'google-storage', 'huawei-obs', 'local', 'oci-storage', 'opendal', 's3', 'supabase', 'tencent-cos', 'volcengine-tos']` [bad-assignment]
   --> configs/middleware/__init__.py:69:9
 ERROR `str` is not assignable to `Literal['advanced-chat', 'agent-chat', 'all', 'channel', 'chat', 'completion', 'workflow']` [bad-assignment]
-  --> controllers/console/app/app.py:68:104
+  --> controllers/console/app/app.py:69:104
 ERROR Object of class `App` has no attribute `access_mode` [missing-attribute]
-   --> controllers/console/app/app.py:573:13
+   --> controllers/console/app/app.py:574:13
 ERROR Argument `str | None` is not assignable to parameter `language` with type `str` in function `services.account_service.AccountService.send_email_register_email` [bad-argument-type]
   --> controllers/console/auth/email_register.py:75:108
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]

@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 0.00% 41.39% +41.39%
Strict coverage 0.00% 40.91% +40.91%
Typed symbols 0 20,736 +20,736
Untyped symbols 0 29,708 +29,708
Modules 0 2538 +2,538

Copilot AI 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.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Refactors app tracing config retrieval to use dependency-injected DB sessions, aligning with the “one session per HTTP endpoint” pattern and avoiding nested session usage.

Changes:

  • Update OpsTraceManager.get_app_tracing_config to accept an injected SQLAlchemy Session.
  • Adjust console controller to create and pass a session per request.
  • Update unit tests to pass a mocked session object into the updated API.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
api/tests/unit_tests/core/ops/test_ops_trace_manager.py Updates unit tests to pass the injected session argument.
api/core/ops/ops_trace_manager.py Changes tracing-config fetch to use an injected Session instead of a global session.
api/controllers/console/app/app.py Creates a per-request session and injects it into OpsTraceManager.get_app_tracing_config.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread api/core/ops/ops_trace_manager.py Resolved
Comment thread api/core/ops/ops_trace_manager.py Resolved
Comment thread api/controllers/console/app/app.py Resolved
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-05-08 10:37:50.226564345 +0000
+++ /tmp/pyrefly_pr.txt	2026-05-08 10:37:39.074492153 +0000
@@ -3,9 +3,9 @@
 ERROR `str` is not assignable to `Literal['aliyun-oss', 'azure-blob', 'baidu-obs', 'clickzetta-volume', 'google-storage', 'huawei-obs', 'local', 'oci-storage', 'opendal', 's3', 'supabase', 'tencent-cos', 'volcengine-tos']` [bad-assignment]
   --> configs/middleware/__init__.py:69:9
 ERROR `str` is not assignable to `Literal['advanced-chat', 'agent-chat', 'all', 'channel', 'chat', 'completion', 'workflow']` [bad-assignment]
-  --> controllers/console/app/app.py:68:104
+  --> controllers/console/app/app.py:69:104
 ERROR Object of class `App` has no attribute `access_mode` [missing-attribute]
-   --> controllers/console/app/app.py:573:13
+   --> controllers/console/app/app.py:574:13
 ERROR Argument `str | None` is not assignable to parameter `language` with type `str` in function `services.account_service.AccountService.send_email_register_email` [bad-argument-type]
   --> controllers/console/auth/email_register.py:75:108
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:S This PR changes 10-29 lines, ignoring generated files. labels May 8, 2026
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-05-08 10:42:56.724062898 +0000
+++ /tmp/pyrefly_pr.txt	2026-05-08 10:42:46.798953894 +0000
@@ -3,9 +3,9 @@
 ERROR `str` is not assignable to `Literal['aliyun-oss', 'azure-blob', 'baidu-obs', 'clickzetta-volume', 'google-storage', 'huawei-obs', 'local', 'oci-storage', 'opendal', 's3', 'supabase', 'tencent-cos', 'volcengine-tos']` [bad-assignment]
   --> configs/middleware/__init__.py:69:9
 ERROR `str` is not assignable to `Literal['advanced-chat', 'agent-chat', 'all', 'channel', 'chat', 'completion', 'workflow']` [bad-assignment]
-  --> controllers/console/app/app.py:68:104
+  --> controllers/console/app/app.py:69:104
 ERROR Object of class `App` has no attribute `access_mode` [missing-attribute]
-   --> controllers/console/app/app.py:573:13
+   --> controllers/console/app/app.py:574:13
 ERROR Argument `str | None` is not assignable to parameter `language` with type `str` in function `services.account_service.AccountService.send_email_register_email` [bad-argument-type]
   --> controllers/console/auth/email_register.py:75:108
 ERROR Object of class `MissingRouter` has no attribute `get` [missing-attribute]

@asukaminato0721
asukaminato0721 added this pull request to the merge queue May 8, 2026
@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label May 8, 2026
Merged via the queue into langgenius:main with commit 19bf36a May 8, 2026
27 checks passed
@asukaminato0721
asukaminato0721 deleted the 24138 branch May 8, 2026 17:58
@dosubot dosubot Bot mentioned this pull request May 24, 2026
@asukaminato0721 asukaminato0721 mentioned this pull request Jun 25, 2026
5 tasks
Ssazurov pushed a commit to Ssazurov/dify that referenced this pull request Aug 8, 2026
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants