Repository navigation
chore: pass session explicitly in ApiModeration - #39885
Merged
asukaminato0721 merged 1 commit intoAug 3, 2026
Merged
Conversation
Make the DB session an explicit parameter of ApiModeration._get_api_based_extension instead of relying on the implicit global db.session inside the query function, following the pattern from langgenius#37402. Callers (validate_config and _get_config_by_requestor) now pass db.session at the call site, so the session dependency of the leaf query is visible in the signature. The other moderation providers (keywords, openai_moderation) do not query the database, so the factory boundary and their signatures stay unchanged. langgenius#37403
asukaminato0721
enabled auto-merge
August 3, 2026 02:17
asukaminato0721
approved these changes
Aug 3, 2026
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-08-03 02:18:39.069353980 +0000
+++ /tmp/pyrefly_pr.txt 2026-08-03 02:18:29.392275322 +0000
@@ -4525,7 +4525,11 @@
ERROR Argument `_FakeModelRuntime` is not assignable to parameter `runtime` with type `ModelRuntime` in function `core.plugin.impl.model_runtime_factory.create_model_type_instance` [bad-argument-type]
--> tests/unit_tests/core/model_runtime/test_model_provider_factory.py:422:21
ERROR Missing argument `text` in function `core.moderation.api.api.ModerationOutputParams.__init__` [missing-argument]
- --> tests/unit_tests/core/moderation/api/test_api.py:58:35
+ --> tests/unit_tests/core/moderation/api/test_api.py:49:35
+ERROR Argument `Session` is not assignable to parameter `session` with type `scoped_session[Unknown]` in function `core.moderation.api.api.ApiModeration._get_api_based_extension` [bad-argument-type]
+ --> tests/unit_tests/core/moderation/api/test_api.py:189:78
+ERROR Argument `Session` is not assignable to parameter `session` with type `scoped_session[Unknown]` in function `core.moderation.api.api.ApiModeration._get_api_based_extension` [bad-argument-type]
+ --> tests/unit_tests/core/moderation/api/test_api.py:192:76
ERROR Argument `Literal['invalid']` is not assignable to parameter `config` with type `dict[str, Any] | None` in function `core.moderation.base.Moderation.__init__` [bad-argument-type]
--> tests/unit_tests/core/moderation/test_sensitive_word_filter.py:1282:92
ERROR Class member `ConcreteTraceInstance.trace` overrides a member in a parent class but is missing an `@override` decorator [missing-override-decorator]
@@ -7565,25 +7569,25 @@
ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset_process_rule` with type `DatasetProcessRule | None` in function `services.dataset_service.DocumentService.save_document_with_dataset_id` [bad-argument-type]
--> tests/unit_tests/services/test_dataset_service_document.py:952:38
ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset_process_rule` with type `DatasetProcessRule | None` in function `services.dataset_service.DocumentService.save_document_with_dataset_id` [bad-argument-type]
- --> tests/unit_tests/services/test_dataset_service_document.py:1034:38
+ --> tests/unit_tests/services/test_dataset_service_document.py:1033:38
ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset_process_rule` with type `DatasetProcessRule | None` in function `services.dataset_service.DocumentService.save_document_with_dataset_id` [bad-argument-type]
- --> tests/unit_tests/services/test_dataset_service_document.py:1086:38
+ --> tests/unit_tests/services/test_dataset_service_document.py:1085:38
ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `services.dataset_service.DocumentService.update_document_with_dataset_id` [bad-argument-type]
- --> tests/unit_tests/services/test_dataset_service_document.py:1242:17
+ --> tests/unit_tests/services/test_dataset_service_document.py:1241:17
ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `services.dataset_service.DocumentService.update_document_with_dataset_id` [bad-argument-type]
- --> tests/unit_tests/services/test_dataset_service_document.py:1275:21
+ --> tests/unit_tests/services/test_dataset_service_document.py:1274:21
ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `services.dataset_service.DocumentService.update_document_with_dataset_id` [bad-argument-type]
- --> tests/unit_tests/services/test_dataset_service_document.py:1303:21
+ --> tests/unit_tests/services/test_dataset_service_document.py:1302:21
ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `services.dataset_service.DocumentService.update_document_with_dataset_id` [bad-argument-type]
- --> tests/unit_tests/services/test_dataset_service_document.py:1324:21
+ --> tests/unit_tests/services/test_dataset_service_document.py:1323:21
ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `services.dataset_service.DocumentService.update_document_with_dataset_id` [bad-argument-type]
- --> tests/unit_tests/services/test_dataset_service_document.py:1364:17
+ --> tests/unit_tests/services/test_dataset_service_document.py:1363:17
ERROR Object of class `NoneType` has no attribute `rules` [missing-attribute]
- --> tests/unit_tests/services/test_dataset_service_document.py:1743:22
+ --> tests/unit_tests/services/test_dataset_service_document.py:1742:22
ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset_process_rule` with type `DatasetProcessRule | None` in function `services.dataset_service.DocumentService.save_document_with_dataset_id` [bad-argument-type]
- --> tests/unit_tests/services/test_dataset_service_document.py:1873:42
+ --> tests/unit_tests/services/test_dataset_service_document.py:1872:42
ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset_process_rule` with type `DatasetProcessRule | None` in function `services.dataset_service.DocumentService.save_document_with_dataset_id` [bad-argument-type]
- --> tests/unit_tests/services/test_dataset_service_document.py:1897:42
+ --> tests/unit_tests/services/test_dataset_service_document.py:1896:42
ERROR Argument `SimpleNamespace` is not assignable to parameter `knowledge_config` with type `KnowledgeConfig` in function `services.dataset_service.DocumentService.save_document_with_dataset_id` [bad-argument-type]
--> tests/unit_tests/services/test_dataset_service_lock_not_owned.py:125:26
ERROR Argument `SimpleNamespace` is not assignable to parameter `dataset` with type `Dataset` in function `services.dataset_service.SegmentService.create_child_chunk` [bad-argument-type]
|
Contributor
Pyrefly Type Coverage
|
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
For #37403 — make the DB session an explicit parameter in the moderation module, following the pattern from #37402.
ApiModeration._get_api_based_extensionnow takessession: scoped_sessionand uses it for the query, instead of relying on the implicit globaldb.sessioninside the leaf function.validate_configand_get_config_by_requestor) passdb.sessionat the call site, so the session dependency of the leaf query is visible in the signature.keywords,openai_moderation) do not query the database, so the factory boundary and their signatures stay unchanged.Testing
uv run --project api pytest api/tests/unit_tests/core/moderation -q→ 208 passedruff check/ruff format --checkon touched files → passpyrefly checkon touched files → 0 errorsFrom CodeBuddy Code