From 4b839f9c5e028999d62e08ff3d1b809f399e0466 Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Fri, 6 Feb 2026 09:23:46 -0800 Subject: [PATCH] fix: skip budget lookup failure log for expected user-not-found case Avoid logging 'cache will not be populated' when the user simply doesn't exist - not caching is correct behavior in that case. Only log for unexpected errors (schema, DB, etc.) where the message is meaningful. --- litellm/proxy/auth/auth_checks.py | 7 ++++++- tests/test_litellm/proxy/auth/test_auth_checks.py | 10 +++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.py index 7ae906e7a7d..92e98d6446e 100644 --- a/litellm/proxy/auth/auth_checks.py +++ b/litellm/proxy/auth/auth_checks.py @@ -79,8 +79,13 @@ def _log_budget_lookup_failure(entity: str, error: Exception) -> None: """ Log a warning when budget lookup fails; cache will not be populated. - Adds a schema migration hint when the error appears schema-related. + Skips logging for expected "user not found" cases (bare Exception from + get_user_object when user_id_upsert=False). Adds a schema migration hint + when the error appears schema-related. """ + # Skip logging for expected "user not found" - not caching is correct + if str(error) == "" and type(error).__name__ == "Exception": + return err_str = str(error).lower() hint = "" if any( diff --git a/tests/test_litellm/proxy/auth/test_auth_checks.py b/tests/test_litellm/proxy/auth/test_auth_checks.py index 7ca3696302a..4f8e80c023e 100644 --- a/tests/test_litellm/proxy/auth/test_auth_checks.py +++ b/tests/test_litellm/proxy/auth/test_auth_checks.py @@ -275,7 +275,7 @@ async def test_default_internal_user_params_with_get_user_object(monkeypatch): def test_log_budget_lookup_failure_dry_run(): - """Dry run: verify _log_budget_lookup_failure logs without raising.""" + """Dry run: verify _log_budget_lookup_failure logs for schema/DB errors.""" with patch("litellm.proxy.auth.auth_checks.verbose_proxy_logger") as mock_logger: err = Exception("column 'policies' does not exist in prisma schema") _log_budget_lookup_failure("user", err) @@ -287,6 +287,14 @@ def test_log_budget_lookup_failure_dry_run(): assert "prisma db push" in call_msg +def test_log_budget_lookup_failure_skips_user_not_found(): + """Verify _log_budget_lookup_failure does NOT log for expected user-not-found.""" + with patch("litellm.proxy.auth.auth_checks.verbose_proxy_logger") as mock_logger: + err = Exception() # bare Exception from get_user_object when user not found + _log_budget_lookup_failure("user", err) + mock_logger.error.assert_not_called() + + @pytest.mark.asyncio @patch("litellm.proxy.management_endpoints.team_endpoints.new_team", new_callable=AsyncMock) async def test_get_team_db_check_calls_new_team_on_upsert(mock_new_team, monkeypatch):