Skip to content

refactor(controllers): adopt with_session in web saved_message - #41859

Merged
asukaminato0721 merged 2 commits into
langgenius:mainfrom
yuki-uix:refactor/db-session-web-saved-message
Sep 7, 2026
Merged

asukaminato0721 merged 2 commits into
langgenius:mainfrom
yuki-uix:refactor/db-session-web-saved-message

Conversation

@yuki-uix

@yuki-uix yuki-uix commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

Part of #37403

Replaces the three inline db.session() calls in api/controllers/web/saved_message.py with the existing @with_session decorator, so each handler owns one session with an explicit commit/rollback boundary instead of reaching for the scoped session at every call site. SavedMessageService already accepts an explicit session, so this is the controller-side follow-up.

  • SavedMessageListApi.get uses @with_session(write=False) (read-only)
  • SavedMessageListApi.post and SavedMessageApi.delete use @with_session
  • Drops the extensions.ext_database import
  • Updates the unit tests, which call the unwrapped handlers and now pass a stub session
  • Follows the pattern already used in api/controllers/web/message.py

Verified: check_no_new_controller_sqlalchemy.py clean, lint-imports 26/26 kept, ruff check + format clean, pyrefly clean, pytest tests/unit_tests/controllers 3960 passed.

Replace the three inline db.session() calls with the existing
with_session decorator so each handler owns one session with an
explicit commit/rollback boundary.
@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-09-07 05:30:32.838099153 +0000
+++ /tmp/pyrefly_pr.txt	2026-09-07 05:30:24.382057037 +0000
@@ -3333,19 +3333,19 @@
 ERROR Argument `Iterator[Any]` is not assignable to parameter `response` with type `Generator[str] | RateLimitGenerator` in function `controllers.console.app.completion._drain_streaming_generate_response` [bad-argument-type]
     --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:1800:66
 ERROR Object of class `object` has no attribute `data` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2222:50
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2212:50
 ERROR Object of class `object` has no attribute `limit` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2223:30
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2213:30
 ERROR Object of class `object` has no attribute `has_more` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2224:33
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2214:33
 ERROR Object of class `object` has no attribute `data` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2267:50
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2251:50
 ERROR Object of class `object` has no attribute `limit` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2268:30
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2252:30
 ERROR Object of class `object` has no attribute `has_more` [missing-attribute]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2269:33
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2253:33
 ERROR Argument `Literal['00000000-0000-0000-0000-000000000002']` is not assignable to parameter `message_id` with type `UUID` in function `controllers.console.app.message._get_message_suggested_questions` [bad-argument-type]
-    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2371:24
+    --> tests/unit_tests/controllers/console/agent/test_agent_controllers.py:2350:24
 ERROR Object of class `int` has no attribute `lower` [missing-attribute]
    --> tests/unit_tests/controllers/console/app/test_annotation_security.py:237:38
 ERROR Object of class `int` has no attribute `lower` [missing-attribute]
@@ -3375,13 +3375,13 @@
 ERROR Cannot index into `object` [bad-index]
    --> tests/unit_tests/controllers/console/app/test_audio.py:158:17
 ERROR Argument `SimpleNamespace` is not assignable to parameter `current_user` with type `Account` in function `controllers.console.app.message._update_message_feedback` [bad-argument-type]
-   --> tests/unit_tests/controllers/console/app/test_message_api.py:128:26
+   --> tests/unit_tests/controllers/console/app/test_message_api.py:115:26
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.message._update_message_feedback` [bad-argument-type]
-   --> tests/unit_tests/controllers/console/app/test_message_api.py:129:23
+   --> tests/unit_tests/controllers/console/app/test_message_api.py:116:23
 ERROR Argument `SimpleNamespace` is not assignable to parameter `app_model` with type `App` in function `controllers.console.app.message._get_message_detail` [bad-argument-type]
-   --> tests/unit_tests/controllers/console/app/test_message_api.py:151:19
+   --> tests/unit_tests/controllers/console/app/test_message_api.py:138:19
 ERROR Argument `Literal['550e8400-e29b-41d4-a716-446655440000']` is not assignable to parameter `message_id` with type `UUID` in function `controllers.console.app.message._get_message_detail` [bad-argument-type]
-   --> tests/unit_tests/controllers/console/app/test_message_api.py:152:20
+   --> tests/unit_tests/controllers/console/app/test_message_api.py:139:20
 ERROR Argument `list[FromClause]` is not assignable to parameter `tables` with type `Sequence[Table] | None` in function `sqlalchemy.sql.schema.MetaData.create_all` [bad-argument-type]
   --> tests/unit_tests/controllers/console/app/test_model_config_api.py:89:51
 ERROR Argument `str | None` is not assignable to parameter `s` with type `bytearray | bytes | str` in function `json.loads` [bad-argument-type]
@@ -3584,8 +3584,6 @@
    --> tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py:388:35
 ERROR Missing argument `payload` in function `protected_view` [missing-argument]
    --> tests/unit_tests/controllers/inner_api/plugin/test_plugin_wraps.py:394:36
-ERROR Object of class `Resource` has no attribute `post` [missing-attribute]
-   --> tests/unit_tests/controllers/inner_api/workspace/test_workspace.py:364:17
 ERROR Object of class `FromClause` has no attribute `create` [missing-attribute]
   --> tests/unit_tests/controllers/mcp/test_mcp.py:38:13
 ERROR `SimpleNamespace` is not assignable to attribute `mcp_ns` with type `Namespace` [bad-assignment]

@github-actions

github-actions Bot commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 63.52% 63.51% -0.01%
Strict coverage 63.13% 63.12% -0.01%
Typed symbols 45,149 45,132 -17
Untyped symbols 26,087 26,087 0
Modules 3363 3362 -1

@asukaminato0721
asukaminato0721 added this pull request to the merge queue Sep 7, 2026
Merged via the queue into langgenius:main with commit 5e51fe2 Sep 7, 2026
45 checks passed
@yuki-uix
yuki-uix deleted the refactor/db-session-web-saved-message branch September 7, 2026 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants