From 8429e0b874f6f98ac594742e27994fb827772684 Mon Sep 17 00:00:00 2001 From: Ishan Katoch <98383932+ishan-1010@users.noreply.github.com> Date: Tue, 29 Sep 2026 15:13:04 +0530 Subject: [PATCH] fix(proxy): _strip_prisma_query_params drops host, breaking every Unix-socket Postgres deployment _strip_prisma_query_params filters DATABASE_URL through an allowlist of libpq parameters before handing it to psycopg. host was not in that allowlist, so it got stripped. host is a libpq parameter, and passing an absolute path in it is the documented way to select a Unix socket. The function's own docstring says it exists so psycopg can parse the URL, but psycopg parses host correctly, the allowlist is what broke it. A Unix socket is how managed Postgres is reached on Cloud Run, App Engine, and Cloud Functions. Stripping host from a Cloud SQL URL (postgresql://user:pass@localhost/db?host=/cloudsql/project:region:instance) leaves the netloc reading @localhost, so psycopg connects to localhost:5432 where nothing is listening. The Prisma CLI gets the URL untouched and works fine, so migrations apply and the breakage stays invisible until something else that goes through this stripped URL needs the socket. Added host, hostaddr, and port to libpq_params, they are the same class of parameter and have the same problem. fixes #43578 --- .../litellm_proxy_extras/utils.py | 3 +++ .../tests/test_setup_database_fail_fast.py | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/litellm-proxy-extras/litellm_proxy_extras/utils.py b/litellm-proxy-extras/litellm_proxy_extras/utils.py index 8a83c786e02..71c071c69c4 100644 --- a/litellm-proxy-extras/litellm_proxy_extras/utils.py +++ b/litellm-proxy-extras/litellm_proxy_extras/utils.py @@ -656,6 +656,9 @@ class ProxyExtrasDBManager: if not parsed.query: return url libpq_params = { + "host", + "hostaddr", + "port", "sslmode", "sslcert", "sslkey", diff --git a/litellm-proxy-extras/tests/test_setup_database_fail_fast.py b/litellm-proxy-extras/tests/test_setup_database_fail_fast.py index 832075f6fbe..548bdc924ba 100644 --- a/litellm-proxy-extras/tests/test_setup_database_fail_fast.py +++ b/litellm-proxy-extras/tests/test_setup_database_fail_fast.py @@ -71,6 +71,24 @@ def test_strip_prisma_query_params_passthrough_no_query(): assert ProxyExtrasDBManager._strip_prisma_query_params(url) == url +def test_strip_prisma_query_params_keeps_unix_socket_host(): + """A Cloud SQL-style Unix socket path in `host` must survive stripping, + it is the documented way to select a Unix socket, not a Prisma-only param.""" + url = "postgresql://user:pass@localhost/litellm?host=/cloudsql/project:region:instance" + stripped = ProxyExtrasDBManager._strip_prisma_query_params(url) + assert "host=" in stripped + assert "%2Fcloudsql%2Fproject%3Aregion%3Ainstance" in stripped + + +def test_strip_prisma_query_params_keeps_hostaddr_and_port(): + """hostaddr and port are the same class of libpq param as host.""" + url = "postgresql://u:p@h:5432/db?hostaddr=10.0.0.5&port=6543&connection_limit=100" + stripped = ProxyExtrasDBManager._strip_prisma_query_params(url) + assert "hostaddr=10.0.0.5" in stripped + assert "port=6543" in stripped + assert "connection_limit" not in stripped + + def test_migration_timestamp_extracts_leading_digits(): assert _migration_timestamp("20260101000000_add_foo") == 20260101000000 assert _migration_timestamp("20250326162113_baseline") == 20250326162113