From 003909d325afc09c446a96b2730871c7f3868f33 Mon Sep 17 00:00:00 2001 From: AxelRay <110029405+axelray-dev@users.noreply.github.com> Date: Fri, 25 Sep 2026 04:14:21 +0800 Subject: [PATCH] fix(activity): fail closed on deleted key lookup errors --- .../management_endpoints/common_daily_activity.py | 12 ++++-------- .../test_common_daily_activity.py | 3 ++- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/litellm/proxy/management_endpoints/common_daily_activity.py b/litellm/proxy/management_endpoints/common_daily_activity.py index 329fef4260d..3a808327b8d 100644 --- a/litellm/proxy/management_endpoints/common_daily_activity.py +++ b/litellm/proxy/management_endpoints/common_daily_activity.py @@ -564,14 +564,10 @@ async def _get_deleted_keys_for_user( prisma_client: PrismaClient, user_id: str, ) -> Sequence["PrismaDeletedVerificationToken"]: - try: - return await DeletedVerificationTokenRepository(prisma_client).table.find_many( - where={"user_id": user_id}, # mutable-ok: Prisma query payload is consumed as a mutable mapping - order={"deleted_at": "desc"}, # mutable-ok: Prisma query payload is consumed as a mutable mapping - ) - except Exception as e: - verbose_proxy_logger.warning("Failed to fetch deleted key metadata for user %s: %s", user_id, e) - return () + return await DeletedVerificationTokenRepository(prisma_client).table.find_many( + where={"user_id": user_id}, # mutable-ok: Prisma query payload is consumed as a mutable mapping + order={"deleted_at": "desc"}, # mutable-ok: Prisma query payload is consumed as a mutable mapping + ) async def get_user_api_key_filter( diff --git a/tests/test_litellm/proxy/management_endpoints/test_common_daily_activity.py b/tests/test_litellm/proxy/management_endpoints/test_common_daily_activity.py index 84f9cc202de..9a61c7ac5dd 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_common_daily_activity.py +++ b/tests/test_litellm/proxy/management_endpoints/test_common_daily_activity.py @@ -355,7 +355,8 @@ async def test_get_user_api_key_filter_handles_deleted_lookup_failure_and_owned_ side_effect=RuntimeError("deleted-key table unavailable") ) - assert await get_user_api_key_filter(mock_prisma, "target-user", "active-key") == ["active-key"] + with pytest.raises(RuntimeError, match="deleted-key table unavailable"): + await get_user_api_key_filter(mock_prisma, "target-user", "active-key") @pytest.mark.asyncio