Skip to content

refactor(api): use sessionmaker in plugin & trigger services#34764

Merged
asukaminato0721 merged 2 commits intolanggenius:mainfrom
carlos4s:refactor/sessionmaker-plugin-trigger-services
Apr 8, 2026
Merged

refactor(api): use sessionmaker in plugin & trigger services#34764
asukaminato0721 merged 2 commits intolanggenius:mainfrom
carlos4s:refactor/sessionmaker-plugin-trigger-services

Conversation

@carlos4s
Copy link
Copy Markdown
Contributor

@carlos4s carlos4s commented Apr 8, 2026

Summary

  • Replace with Session(db.engine) + session.commit() with sessionmaker(bind=db.engine).begin()
    context manager for automatic transaction management in plugin and trigger services
  • Updated corresponding test mocks from Session to sessionmaker pattern

Files changed:

  • api/services/plugin/plugin_permission_service.py
  • api/services/plugin/plugin_auto_upgrade_service.py
  • api/services/trigger/app_trigger_service.py
  • api/services/trigger/trigger_service.py
  • api/services/trigger/webhook_service.py
  • 3 test files (mock updates)

Part of #24245

Test plan

  • ruff check passes
  • ruff format --check passes
  • 2482 unit tests pass

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. refactor labels Apr 8, 2026
@carlos4s carlos4s force-pushed the refactor/sessionmaker-plugin-trigger-services branch from 81ed08e to d5e8005 Compare April 8, 2026 19:02
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-08 19:01:53.806132434 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-08 19:01:46.304025634 +0000
@@ -6679,29 +6679,29 @@
 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]
    --> tests/unit_tests/services/test_webhook_service.py:535:83
 ERROR Argument `dict[str, dict[str, str] | str]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService._validate_http_metadata` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1021:53
+    --> tests/unit_tests/services/test_webhook_service.py:1024:53
 ERROR Argument `dict[str, dict[str, int] | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.build_workflow_inputs` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1044:51
+    --> tests/unit_tests/services/test_webhook_service.py:1047:51
 ERROR Argument `dict[str, dict[str, int]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.trigger_workflow_execution` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1077:64
+    --> tests/unit_tests/services/test_webhook_service.py:1080:64
 ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1290:61
+    --> tests/unit_tests/services/test_webhook_service.py:1292:61
 ERROR Missing required key `id` for TypedDict `NodeConfigDict` [bad-typed-dict-key]
     --> tests/unit_tests/services/test_workflow_service.py:2682:71
 ERROR Missing required key `data` for TypedDict `NodeConfigDict` [bad-typed-dict-key]

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-08 19:03:37.301172772 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-08 19:03:27.428259767 +0000
@@ -6679,29 +6679,29 @@
 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]
    --> tests/unit_tests/services/test_webhook_service.py:535:83
 ERROR Argument `dict[str, dict[str, str] | str]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService._validate_http_metadata` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1021:53
+    --> tests/unit_tests/services/test_webhook_service.py:1024:53
 ERROR Argument `dict[str, dict[str, int] | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.build_workflow_inputs` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1044:51
+    --> tests/unit_tests/services/test_webhook_service.py:1047:51
 ERROR Argument `dict[str, dict[str, int]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.trigger_workflow_execution` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1077:64
+    --> tests/unit_tests/services/test_webhook_service.py:1080:64
 ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1290:61
+    --> tests/unit_tests/services/test_webhook_service.py:1292:61
 ERROR Missing required key `id` for TypedDict `NodeConfigDict` [bad-typed-dict-key]
     --> tests/unit_tests/services/test_workflow_service.py:2682:71
 ERROR Missing required key `data` for TypedDict `NodeConfigDict` [bad-typed-dict-key]

@carlos4s carlos4s force-pushed the refactor/sessionmaker-plugin-trigger-services branch from d5e8005 to 9c3b873 Compare April 8, 2026 19:33
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-08 19:35:02.566911997 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-08 19:34:53.879865361 +0000
@@ -6679,29 +6679,29 @@
 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]
    --> tests/unit_tests/services/test_webhook_service.py:535:83
 ERROR Argument `dict[str, dict[str, str] | str]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService._validate_http_metadata` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1021:53
+    --> tests/unit_tests/services/test_webhook_service.py:1024:53
 ERROR Argument `dict[str, dict[str, int] | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.build_workflow_inputs` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1044:51
+    --> tests/unit_tests/services/test_webhook_service.py:1047:51
 ERROR Argument `dict[str, dict[str, int]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.trigger_workflow_execution` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1077:64
+    --> tests/unit_tests/services/test_webhook_service.py:1080:64
 ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1117:68
 ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1142:68
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1290:61
+    --> tests/unit_tests/services/test_webhook_service.py:1292:61
 ERROR Missing required key `id` for TypedDict `NodeConfigDict` [bad-typed-dict-key]
     --> tests/unit_tests/services/test_workflow_service.py:2682:71
 ERROR Missing required key `data` for TypedDict `NodeConfigDict` [bad-typed-dict-key]

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 8, 2026

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-04-08 19:53:23.818411792 +0000
+++ /tmp/pyrefly_pr.txt	2026-04-08 19:53:14.235520364 +0000
@@ -6679,29 +6679,29 @@
 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]
    --> tests/unit_tests/services/test_webhook_service.py:535:83
 ERROR Argument `dict[str, dict[str, str] | str]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService._validate_http_metadata` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1021:53
+    --> tests/unit_tests/services/test_webhook_service.py:1036:53
 ERROR Argument `dict[str, dict[str, int] | dict[str, str]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.build_workflow_inputs` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1044:51
+    --> tests/unit_tests/services/test_webhook_service.py:1059:51
 ERROR Argument `dict[str, dict[str, int]]` is not assignable to parameter `webhook_data` with type `RawWebhookDataDict` in function `services.trigger.webhook_service.WebhookService.trigger_workflow_execution` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1077:64
+    --> tests/unit_tests/services/test_webhook_service.py:1092:64
 ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1129:68
 ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1129:68
 ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1129:68
 ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1114:68
+    --> tests/unit_tests/services/test_webhook_service.py:1129:68
 ERROR Missing required key `method` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1154:68
 ERROR Missing required key `headers` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1154:68
 ERROR Missing required key `query_params` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1154:68
 ERROR Missing required key `files` for TypedDict `RawWebhookDataDict` [bad-typed-dict-key]
-    --> tests/unit_tests/services/test_webhook_service.py:1139:68
+    --> tests/unit_tests/services/test_webhook_service.py:1154:68
 ERROR Argument `dict[str, dict[str, int | str]]` is not assignable to parameter `node_config` with type `NodeConfigDict` in function `services.trigger.webhook_service.WebhookService.generate_webhook_response` [bad-argument-type]
-    --> tests/unit_tests/services/test_webhook_service.py:1290:61
+    --> tests/unit_tests/services/test_webhook_service.py:1304:61
 ERROR Missing required key `id` for TypedDict `NodeConfigDict` [bad-typed-dict-key]
     --> tests/unit_tests/services/test_workflow_service.py:2682:71
 ERROR Missing required key `data` for TypedDict `NodeConfigDict` [bad-typed-dict-key]

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 8, 2026
@asukaminato0721 asukaminato0721 added this pull request to the merge queue Apr 8, 2026
Merged via the queue into langgenius:main with commit 1d971d3 Apr 8, 2026
27 checks passed
@carlos4s carlos4s deleted the refactor/sessionmaker-plugin-trigger-services branch April 9, 2026 02:34
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