From 4fee71b7ad991b2c1c1af0e6aa5b33f18ab57c97 Mon Sep 17 00:00:00 2001 From: yassin Date: Mon, 14 Sep 2026 20:10:36 +0000 Subject: [PATCH] fix(proxy): define UserNotFoundError in an import-free types module so no importer sits in the CodeQL cycle Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/proxy/_types.py | 7 ------- litellm/proxy/auth/auth_checks.py | 2 +- litellm/proxy/management_endpoints/team_endpoints.py | 2 +- litellm/types/proxy/auth/auth_checks.py | 8 ++++++++ 4 files changed, 10 insertions(+), 9 deletions(-) create mode 100644 litellm/types/proxy/auth/auth_checks.py diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index 412b902febc..49e0247aad9 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -3954,13 +3954,6 @@ class ManagementEndpointLoggingPayload(LiteLLMPydanticObjectBase): end_time: datetime | None = None -class UserNotFoundError(ValueError): - """The user row is provably absent, as opposed to merely unreadable, so a caller that reads a missing row as no user-level limits can key on it without also swallowing a database that would not answer.""" - - def __init__(self, user_id: str) -> None: - super().__init__(f"User doesn't exist in db. 'user_id'={user_id}. Create user via `/user/new` call.") - - class ProxyException(Exception): # NOTE: DO NOT MODIFY THIS # This is used to map exactly to OPENAI Exceptions diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.py index 6f4e5cd3ca1..0cbb4a38aba 100644 --- a/litellm/proxy/auth/auth_checks.py +++ b/litellm/proxy/auth/auth_checks.py @@ -65,7 +65,6 @@ from litellm.proxy._types import ( RoleBasedPermissions, SpecialModelNames, UserAPIKeyAuth, - UserNotFoundError, ) from litellm.proxy.auth.budget_throttle import ( budget_throttle_percentage, @@ -124,6 +123,7 @@ from litellm.repositories.table_repositories import ( from litellm.repositories.team_repository import TeamRepository from litellm.repositories.user_repository import UserRepository from litellm.router import Router +from litellm.types.proxy.auth.auth_checks import UserNotFoundError from litellm.types.proxy.model_access_group_budget import ModelAccessGroupBudget from litellm.utils import get_utc_datetime diff --git a/litellm/proxy/management_endpoints/team_endpoints.py b/litellm/proxy/management_endpoints/team_endpoints.py index a627c1438dc..6b16692f7ad 100644 --- a/litellm/proxy/management_endpoints/team_endpoints.py +++ b/litellm/proxy/management_endpoints/team_endpoints.py @@ -73,7 +73,6 @@ from litellm.proxy._types import ( TeamModelDeleteRequest, UpdateTeamRequest, UserAPIKeyAuth, - UserNotFoundError, ) from litellm.proxy.auth.auth_checks import ( OrganizationNotFoundError, @@ -157,6 +156,7 @@ from litellm.repositories.verification_token_repository import ( VerificationTokenRepository, ) from litellm.router import Router +from litellm.types.proxy.auth.auth_checks import UserNotFoundError from litellm.types.proxy.management_endpoints.common_daily_activity import ( SpendAnalyticsPaginatedResponse, ) diff --git a/litellm/types/proxy/auth/auth_checks.py b/litellm/types/proxy/auth/auth_checks.py new file mode 100644 index 00000000000..80c65d14113 --- /dev/null +++ b/litellm/types/proxy/auth/auth_checks.py @@ -0,0 +1,8 @@ +"""Failure values raised by `litellm/proxy/auth/auth_checks.py`. Kept free of `litellm` imports so any proxy module can import them without joining the `litellm.proxy` import cycle.""" + + +class UserNotFoundError(ValueError): + """The user row is provably absent, as opposed to merely unreadable, so a caller that reads a missing row as no user-level limits can key on it without also swallowing a database that would not answer.""" + + def __init__(self, user_id: str) -> None: + super().__init__(f"User doesn't exist in db. 'user_id'={user_id}. Create user via `/user/new` call.")