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 greptile reviews and mock test
Sameer Kankute1a0b30aaac02
diff --git a/litellm/proxy/litellm_pre_call_utils.py b/litellm/proxy/litellm_pre_call_utils.pyindex 64ef2405002..f8f299b1481 100644--- a/litellm/proxy/litellm_pre_call_utils.py+++ b/litellm/proxy/litellm_pre_call_utils.py@@ -1,6 +1,7 @@import asyncioimport copyimport time+from collections import OrderedDictfrom typing import TYPE_CHECKING, Any, Dict, List, Optional, Unionfrom fastapi import Request@@ -37,7 +38,9 @@ from litellm.types.utils import ()service_logger_obj = ServiceLogging() # used for tracking latency on OTEL-_STALE_TEAM_ALIAS_WARNING_KEYS: set[str] = set()+# Bounded dedup for stale-alias warnings (FIFO eviction when over cap).+_MAX_STALE_ALIAS_WARNING_KEYS = 10_000+_STALE_TEAM_ALIAS_WARNING_KEYS: OrderedDict[str, None] = OrderedDict()if TYPE_CHECKING:@@ -1335,7 +1338,12 @@ def _update_model_if_team_alias_exists(returnwarning_key = f"{user_api_key_dict.team_id}:{_model}:{aliased_target}"if warning_key not in _STALE_TEAM_ALIAS_WARNING_KEYS:- _STALE_TEAM_ALIAS_WARNING_KEYS.add(warning_key)+ _STALE_TEAM_ALIAS_WARNING_KEYS[warning_key] = None+ while (+ len(_STALE_TEAM_ALIAS_WARNING_KEYS)+ > _MAX_STALE_ALIAS_WARNING_KEYS+ ):+ _STALE_TEAM_ALIAS_WARNING_KEYS.popitem(last=False)verbose_proxy_logger.warning("Stale team model alias detected for model='%s', team_id='%s'. ""New sibling deployments may be unreachable. "diff --git a/litellm/proxy/management_endpoints/model_management_endpoints.py b/litellm/proxy/management_endpoints/model_management_endpoints.pyindex 5952aede853..95c44a431b5 100644--- a/litellm/proxy/management_endpoints/model_management_endpoints.py+++ b/litellm/proxy/management_endpoints/model_management_endpoints.py@@ -495,6 +495,9 @@ async def _update_existing_team_model_assignment()if old_public_name and public_model_name != old_public_name:+ # Clear user-supplied public name from patch before any early return so the+ # caller does not overwrite the internal UUID-based model_name in the DB.+ patch_data.model_name = Noneif prisma_client is None:verbose_proxy_logger.warning("prisma_client not initialized; skipping public name update entirely to avoid orphaned entries"diff --git a/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.pyindex 751d0a02ff0..2a85e24d780 100644--- a/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py+++ b/tests/test_litellm/proxy/management_endpoints/test_model_management_endpoints.py@@ -916,6 +916,41 @@ class TestTeamModelUpdate:mock_add.assert_called_once()mock_delete.assert_not_called()+ @pytest.mark.asyncio+ async def test_rename_with_prisma_none_clears_patch_model_name(self):+ """Rename path must clear patch_data.model_name even when prisma is unavailable (P1)."""+ from litellm.proxy.management_endpoints.model_management_endpoints import (+ _update_existing_team_model_assignment,+ )+ from litellm.types.router import ModelInfo++ db_model = Deployment(+ model_name="model_name_team_123_uuid1",+ litellm_params=LiteLLM_Params(model="azure/gpt-4o-mini"),+ model_info=ModelInfo(+ team_id="team_123", team_public_model_name="old-public-name"+ ),+ )+ patch_data = updateDeployment(+ model_name="new-public-name",+ model_info=ModelInfo(team_id="team_123"),+ )+ user_api_key_dict = UserAPIKeyAuth(+ user_id="test_user",+ user_role=LitellmUserRoles.PROXY_ADMIN,+ )++ await _update_existing_team_model_assignment(+ team_id="team_123",+ public_model_name="new-public-name",+ db_model=db_model,+ patch_data=patch_data,+ user_api_key_dict=user_api_key_dict,+ prisma_client=None,+ )++ assert patch_data.model_name is None+@pytest.mark.asyncioasync def test_rename_handles_legacy_string_model_info(self):"""Test rename path handles legacy string-encoded model_info rows without crashing."""