From 0fda0f9aa2a0ea484f1271e61404cd515fbf516f Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Sat, 31 Jan 2026 09:52:29 -0800 Subject: [PATCH] Fix database query error handling. Previously, query errors returned \None\. That behavior was changed to raise all errors except the query plan cache issue. Raising those errors forces the request down a more expensive fallback path, which can trigger CPU spikes. --- litellm/proxy/utils.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 6bbf0df74de..9c94c62da5a 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -2284,10 +2284,9 @@ class PrismaClient: sql_query: SQL query string to execute Returns: - Query result or None - - Raises: - Original exception if not a cached plan error + Query result or None. Returns None on any DB error other than + the cached-plan error (which is retried once) to preserve + previous behavior where token lookup failures did not raise. """ try: return await self.db.query_first(query=sql_query) @@ -2307,7 +2306,12 @@ class PrismaClient: ) return await self.db.query_first(query=sql_query_retry) else: - raise + # Preserve previous behavior: do not raise on other DB errors; + # return None so caller treats as "no token found" (e.g. 401). + verbose_proxy_logger.debug( + "Token lookup query failed: %s", error_str + ) + return None @backoff.on_exception( backoff.expo,