The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(proxy): handle missing DATABASE_URL in append_query_params (#21239)
Vincent Koc0dcc744f7e45
diff --git a/litellm/proxy/proxy_cli.py b/litellm/proxy/proxy_cli.pyindex 2509a80b140..e91447af895 100644--- a/litellm/proxy/proxy_cli.py+++ b/litellm/proxy/proxy_cli.py@@ -37,11 +37,16 @@ class LiteLLMDatabaseConnectionPool(Enum):database_connection_pool_timeout = 60-def append_query_params(url, params) -> str:+def append_query_params(url: Optional[str], params: dict) -> str:from litellm._logging import verbose_proxy_loggerverbose_proxy_logger.debug(f"url: {url}")verbose_proxy_logger.debug(f"params: {params}")+ if not isinstance(url, str) or url == "":+ # Preserve previous startup behavior when DATABASE_URL is absent.+ # Returning an empty string avoids urlparse type errors in test/dev flows.+ verbose_proxy_logger.warning("append_query_params received empty or non-string URL, returning empty string")+ return ""parsed_url = urlparse.urlparse(url)parsed_query = urlparse.parse_qs(parsed_url.query)parsed_query.update(params)diff --git a/tests/test_litellm/proxy/test_proxy_cli.py b/tests/test_litellm/proxy/test_proxy_cli.pyindex 12065ad5b4d..be91800732b 100644--- a/tests/test_litellm/proxy/test_proxy_cli.py+++ b/tests/test_litellm/proxy/test_proxy_cli.py@@ -218,6 +218,12 @@ class TestProxyInitializationHelpers:assert "connection_limit=10" in modified_urlassert "pool_timeout=60" in modified_url+ def test_append_query_params_handles_missing_url(self):+ from litellm.proxy.proxy_cli import append_query_params++ modified_url = append_query_params(None, {"connection_limit": 10})+ assert modified_url == ""+@patch("uvicorn.run")@patch("atexit.register") # 🔥 criticaldef test_skip_server_startup(self, mock_atexit_register, mock_uvicorn_run):