From fa9585371890f485c8c83f672fed8179b945b103 Mon Sep 17 00:00:00 2001 From: shivam Date: Sat, 7 Feb 2026 17:17:23 -0800 Subject: [PATCH] resolved greptile issue related to regeneration persistence and exception handling --- .../common_daily_activity.py | 8 ++++--- .../key_management_endpoints.py | 23 ++++++++----------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/litellm/proxy/management_endpoints/common_daily_activity.py b/litellm/proxy/management_endpoints/common_daily_activity.py index 79d80abf272..e5df2f82f69 100644 --- a/litellm/proxy/management_endpoints/common_daily_activity.py +++ b/litellm/proxy/management_endpoints/common_daily_activity.py @@ -357,9 +357,11 @@ async def get_api_key_metadata( "key_alias": k.key_alias, "team_id": k.team_id, } - except Exception: - verbose_proxy_logger.debug( - "Failed to fetch deleted key metadata for missing keys" + except Exception as e: + verbose_proxy_logger.warning( + "Failed to fetch deleted key metadata for %d missing keys: %s", + len(missing_keys), + e, ) return result diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index 264dff5aa54..48e0c32880b 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -3313,19 +3313,16 @@ async def regenerate_key_fn( verbose_proxy_logger.debug("key_in_db: %s", _key_in_db) - # Save the old key record to deleted table before regeneration - # This preserves key_alias and team_id metadata for historical spend records - try: - await _persist_deleted_verification_tokens( - keys=[_key_in_db], - prisma_client=prisma_client, - user_api_key_dict=user_api_key_dict, - litellm_changed_by=litellm_changed_by, - ) - except Exception: - verbose_proxy_logger.debug( - "Failed to persist old key record to deleted table during regeneration" - ) + # Save the old key record to deleted table before regeneration. + # This preserves key_alias and team_id metadata for historical spend records. + # If this fails, abort the regeneration to avoid permanently losing the + # old hash→metadata mapping. + await _persist_deleted_verification_tokens( + keys=[_key_in_db], + prisma_client=prisma_client, + user_api_key_dict=user_api_key_dict, + litellm_changed_by=litellm_changed_by, + ) new_token = get_new_token(data=data)