fix: bind hybrid search tsv_lang as a parameter with regconfig cast - #333
Open
Vladislav Nechakhin (vladislav-nechakhin) wants to merge 2 commits into
Open
Vladislav Nechakhin (vladislav-nechakhin) wants to merge 2 commits into
Vladislav Nechakhin (vladislav-nechakhin) wants to merge 2 commits into
Conversation
Interpolating the hybrid search language into to_tsvector and plainto_tsquery as a quoted literal required the value to be a valid text search configuration name. Bind it as a SQLAlchemy parameter with an explicit regconfig cast instead, so the value is always treated as data by PostgreSQL. Unset languages keep the one-argument function forms, so default_text_search_config still applies. Invalid configuration values now surface a PostgreSQL error at query time rather than being spliced into the statement. Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
ccurme (ccurme)
marked this pull request as ready for review
September 16, 2026 16:20
The hybrid search index expression also interpolated the language as a quoted literal, and DDL cannot take a bound parameter. Resolve the language with quote_literal over a regconfig cast before splicing it, so invalid values are rejected by PostgreSQL and the DDL only ever receives the canonical literal. Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
This branch has not been deployed
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.
The two
AsyncPGVectorStorestatements that interpolatehybrid_search_config.tsv_langinto SQL as a quoted literal now bind it as a SQLAlchemy parameter with an explicitregconfigcast, so the value is always treated as data by PostgreSQL:to_tsvector((:tsv_lang)::regconfig, :tsv_content)inaadd_embeddingsplainto_tsquery((:tsv_lang)::regconfig, :fts_query)in the hybrid sparse queryBehavior
tsv_langis unset (Noneor""), both calls keep their one-argument forms and PostgreSQL appliesdefault_text_search_config. No default is substituted.tsvectorvalues are identical for any valid language, so no migration or reindex is needed.tsv_langnow surfaces a PostgreSQL error at query time (e.g.invalid name syntax, SQLSTATE 42602, or "text search configuration ... does not exist") instead of being spliced into the statement text.The cast is wrapped as
(:tsv_lang)::regconfig— the literal:tsv_lang::regconfigis not parsed as a bind parameter by SQLAlchemytext(), so the parentheses are required.Testing
New database-backed tests in
tests/unit_tests/v2/test_async_pg_vectorstore_tsv_lang.pycover the valid language (pg_catalog.english), the unset branch (Noneand""), and the reported payload, asserting the raised error's SQLSTATE is42602(an invalid regconfig literal inside the bound parameter) rather than a statement syntax error. Existing hybrid search tests are unchanged and pass.Follow-up (not in this PR): validating
tsv_langinHybridSearchConfig.__post_init__so a bad value fails at construction instead of at query time.Made by Open SWE · openai:gpt-6-astra (low)
References