chore: pass session explicitly in ApiModeration - #39885
Open
HandSonic wants to merge 1 commit into
Open
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
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