mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-08 22:21:35 +00:00
fix(proxy-extras): read the index repair's target schema from DATABASE_URL
Prisma reads its `schema` query param from DATABASE_URL, and pooler setups keep the schema there while DIRECT_URL is host-only for the pooler bypass. Reading the schema off DIRECT_URL defaulted the catalog lookup to `public` on those configs and left invalid indexes in the real Prisma schema untouched.
This commit is contained in:
parent
2d64020d43
commit
1faa1b445e
2 changed files with 12 additions and 8 deletions
|
|
@ -724,9 +724,12 @@ class ProxyExtrasDBManager:
|
|||
skipped or failed and will be retried on the next startup. Runs over
|
||||
DIRECT_URL when set: the session settings, the advisory lock and REINDEX
|
||||
CONCURRENTLY all need one server session, which a transaction pooler
|
||||
does not give."""
|
||||
database_url: Final = os.getenv("DIRECT_URL") or os.getenv("DATABASE_URL")
|
||||
if not database_url:
|
||||
does not give. The Prisma target schema still comes from DATABASE_URL
|
||||
because that is the URL Prisma reads its `schema` param from, whereas
|
||||
DIRECT_URL is typically the host-only pooler bypass and omits it."""
|
||||
prisma_url: Final = os.getenv("DATABASE_URL")
|
||||
connect_url: Final = os.getenv("DIRECT_URL") or prisma_url
|
||||
if not connect_url:
|
||||
return False
|
||||
|
||||
try:
|
||||
|
|
@ -739,8 +742,10 @@ class ProxyExtrasDBManager:
|
|||
)
|
||||
return False
|
||||
|
||||
schema: Final = ProxyExtrasDBManager._prisma_schema_param(database_url) or "public"
|
||||
cleaned_url: Final = ProxyExtrasDBManager._strip_prisma_query_params(database_url)
|
||||
schema: Final = (
|
||||
ProxyExtrasDBManager._prisma_schema_param(prisma_url) if prisma_url else None
|
||||
) or "public"
|
||||
cleaned_url: Final = ProxyExtrasDBManager._strip_prisma_query_params(connect_url)
|
||||
try:
|
||||
with psycopg.connect(cleaned_url, connect_timeout=10, autocommit=True) as conn:
|
||||
conn.execute("SET statement_timeout = 0")
|
||||
|
|
|
|||
|
|
@ -229,10 +229,9 @@ def test_repair_survives_an_unreachable_database(monkeypatch: pytest.MonkeyPatch
|
|||
@requires_db
|
||||
def test_repair_runs_over_direct_url_when_set(scratch_schema: str) -> None:
|
||||
_leave_invalid_index(scratch_schema, HEALTH_TABLE, HEALTH_INDEX, HEALTH_INDEX_COLUMNS)
|
||||
direct_url: Final = os.environ["DATABASE_URL"]
|
||||
with pytest.MonkeyPatch.context() as env:
|
||||
env.setenv("DIRECT_URL", direct_url)
|
||||
env.setenv("DATABASE_URL", "postgresql://u:p@127.0.0.1:9/x?schema=whatever")
|
||||
env.setenv("DIRECT_URL", _base_url())
|
||||
env.setenv("DATABASE_URL", f"postgresql://u:p@127.0.0.1:9/x?schema={scratch_schema}")
|
||||
assert ProxyExtrasDBManager.repair_invalid_indexes() is True
|
||||
|
||||
assert _index_validity(scratch_schema) == {HEALTH_INDEX: True}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue