fix: apply POSTGRES_SCHEMA search_path to the asyncpg pool - #300
Open
nangelovv wants to merge 1 commit into
Open
fix: apply POSTGRES_SCHEMA search_path to the asyncpg pool#300nangelovv wants to merge 1 commit into
nangelovv wants to merge 1 commit into
Conversation
PSQLDatabase.get_pool() built the asyncpg pool from the bare DSN, so it ran with the default search_path (public) while pgvector's tables live in POSTGRES_SCHEMA (configured on the SQLAlchemy engine). ensure_vector_indexes()'s unqualified DDL then failed at startup with "relation langchain_pg_embedding does not exist" (or silently targeted a stale public table), and the JSONB migration's current_schema() guard never matched the real table — so the schema-isolation feature added in danny-avila#289 was unusable. Pin the asyncpg pool to the same search_path the SQLAlchemy engine uses via server_settings, reusing _build_search_path so the two connection paths cannot drift. No behavior change when POSTGRES_SCHEMA is unset.
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.
What
Pin the asyncpg pool (
PSQLDatabase.get_pool) to the samesearch_paththe SQLAlchemy engine uses whenPOSTGRES_SCHEMAis set, via asyncpgserver_settings.Why
Fixes #299. The pool was built from the bare DSN, so
ensure_vector_indexes()ran inpublicwhile pgvector's tables live inPOSTGRES_SCHEMA→ startup crash (relation "langchain_pg_embedding" does not exist) and a silently-skipped JSON→JSONB migration. Full analysis in the issue.Change
Reuses
_build_search_path/_parse_schemasfrom the vector-store factory so the engine and pool can't drift. No behavior change whenPOSTGRES_SCHEMAis unset (noserver_settingspassed).Testing
tests/services/test_database.py: the pool receivesserver_settings={"search_path": "myapp,public"}for a single schema,"myapp,extensions,public"for a comma-separated list, and noserver_settingswhen unset.tests/services/test_database.py+tests/services/test_vector_store_factory.py: 27 passed.