mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-29 01:42:19 +00:00
fix(proxy): catch HTTPException cleanly on /key/delete to prevent infinite loop logging
This commit is contained in:
parent
6a3333d3c8
commit
155addf3f1
2 changed files with 40 additions and 0 deletions
|
|
@ -3501,6 +3501,8 @@ async def delete_key_fn(
|
|||
|
||||
return {"deleted_keys": deleted_keys}
|
||||
except Exception as e:
|
||||
if isinstance(e, HTTPException):
|
||||
raise handle_exception_on_proxy(e)
|
||||
verbose_proxy_logger.exception("litellm.proxy.proxy_server.delete_key_fn(): Exception occured - %s", e)
|
||||
raise handle_exception_on_proxy(e)
|
||||
|
||||
|
|
@ -4251,6 +4253,8 @@ async def delete_verification_tokens(
|
|||
else:
|
||||
raise Exception("DB not connected. prisma_client is None")
|
||||
except Exception as e:
|
||||
if isinstance(e, HTTPException):
|
||||
raise
|
||||
verbose_proxy_logger.exception(
|
||||
"litellm.proxy.proxy_server.delete_verification_tokens(): Exception occured - %s", e
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5150,6 +5150,42 @@ async def test_delete_key_fn_persists_deleted_keys(monkeypatch):
|
|||
assert result["deleted_keys"] == ["sk-token-1"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_key_fn_404_not_found(monkeypatch):
|
||||
"""Test that deleting a non-existent key raises a 404 cleanly."""
|
||||
from litellm.proxy._types import KeyRequest, ProxyException
|
||||
from litellm.proxy.management_endpoints.key_management_endpoints import delete_key_fn
|
||||
from fastapi import HTTPException
|
||||
|
||||
mock_prisma_client = AsyncMock()
|
||||
mock_user_api_key_cache = MagicMock()
|
||||
|
||||
user_api_key_dict = UserAPIKeyAuth(
|
||||
user_id="admin-user",
|
||||
api_key="sk-admin",
|
||||
user_role=LitellmUserRoles.PROXY_ADMIN.value,
|
||||
)
|
||||
|
||||
# Mock find_many to return an empty list, simulating a key that isn't found
|
||||
mock_prisma_client.verificationtoken.find_many.return_value = []
|
||||
|
||||
monkeypatch.setattr(
|
||||
"litellm.proxy.proxy_server.prisma_client",
|
||||
mock_prisma_client,
|
||||
)
|
||||
|
||||
data = KeyRequest(keys=["sk-nonexistent-key"])
|
||||
|
||||
with pytest.raises(ProxyException) as excinfo:
|
||||
await delete_key_fn(
|
||||
data=data,
|
||||
user_api_key_dict=user_api_key_dict,
|
||||
litellm_changed_by="admin-user",
|
||||
)
|
||||
|
||||
assert "No keys found" in str(excinfo.value)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_can_delete_verification_token_proxy_admin_team_key(monkeypatch):
|
||||
"""Test that team admin can delete team keys from their own team."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue