Skip to content

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]

fix(proxy): return deprecated-key lookup result directly in get_data combined view (#30327)

yuneng-jiang5047eaf7f0e7
diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py
index 4aa555164b0..98d57229a52 100644
--- a/litellm/proxy/utils.py
+++ b/litellm/proxy/utils.py
@@ -3692,7 +3692,10 @@ class PrismaClient:
db=self.db, hashed_token=hashed_token
)
if active_token_id:
- response = await self.get_data(
+ # The recursive call returns a finished
+ # LiteLLM_VerificationTokenView; the dict
+ # normalization below would crash subscripting it.
+ deprecated_response = await self.get_data(
token=active_token_id,
table_name="combined_view",
query_type="find_unique",
@@ -3700,10 +3703,11 @@ class PrismaClient:
proxy_logging_obj=proxy_logging_obj,
check_deprecated=False,
)
- if response is not None:
+ if deprecated_response is not None:
verbose_proxy_logger.debug(
"Deprecated key used during grace period"
)
+ return deprecated_response
if response is not None:
if response["team_models"] is None:
diff --git a/tests/test_litellm/proxy/utils/prisma_and_spend/test_prisma_client_get_data.py b/tests/test_litellm/proxy/utils/prisma_and_spend/test_prisma_client_get_data.py
index 437984d9273..08d1ef619a7 100644
--- a/tests/test_litellm/proxy/utils/prisma_and_spend/test_prisma_client_get_data.py
+++ b/tests/test_litellm/proxy/utils/prisma_and_spend/test_prisma_client_get_data.py
@@ -15,6 +15,7 @@ from __future__ import annotations
import hashlib
import json
+from datetime import datetime, timedelta, timezone
from types import SimpleNamespace
from typing import Any
from unittest.mock import AsyncMock, MagicMock
@@ -22,6 +23,7 @@ from unittest.mock import AsyncMock, MagicMock
import pytest
from fastapi import HTTPException
+from litellm.proxy._types import LiteLLM_VerificationTokenView
from litellm.proxy.utils import PrismaClient
@@ -476,3 +478,39 @@ async def test_get_data_logs_and_raises_on_db_error(
)
with pytest.raises(RuntimeError, match="network split"):
await prisma_client.get_data(token="sk-broken", table_name="key")
+
+
+async def test_get_data_combined_view_returns_view_for_deprecated_key(
+ prisma_client: PrismaClient,
+) -> None:
+ """Grace-period rotation, full get_data flow: the old hash misses the
+ combined view, the deprecated-key table resolves it to the active token,
+ and get_data must return the recursive lookup's finished view instead of
+ re-running dict normalization on it (which raised TypeError and turned
+ every grace-period request into a 401)."""
+ old_hash = "hashed-old-token-grace-e2e"
+ active_hash = "hashed-active-token-grace-e2e"
+ active_row = {
+ "token": active_hash,
+ "team_models": None,
+ "team_blocked": None,
+ "team_members_with_roles": None,
+ "user_id": None,
+ "expires": None,
+ }
+ prisma_client.db.query_first = AsyncMock(side_effect=[None, active_row])
+ prisma_client.db.litellm_deprecatedverificationtoken = MagicMock()
+ prisma_client.db.litellm_deprecatedverificationtoken.find_first = AsyncMock(
+ return_value=SimpleNamespace(
+ active_token_id=active_hash,
+ revoke_at=datetime.now(timezone.utc) + timedelta(hours=1),
+ )
+ )
+
+ response = await prisma_client.get_data(
+ token=old_hash, table_name="combined_view", query_type="find_unique"
+ )
+
+ assert isinstance(response, LiteLLM_VerificationTokenView)
+ assert response.token == active_hash