The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(proxy): remove a bulk-deleted user's email-only roster entries without touching same-email teammates
ryanc25498b66dfe
diff --git a/litellm/proxy/management_helpers/bulk_user_deletion.py b/litellm/proxy/management_helpers/bulk_user_deletion.pyindex d73901a3ea0..92e21a3803b 100644--- a/litellm/proxy/management_helpers/bulk_user_deletion.py+++ b/litellm/proxy/management_helpers/bulk_user_deletion.py@@ -150,16 +150,20 @@ def _org_membership_tx_db(tx: "Prisma") -> "TableActions[prisma_models.LiteLLM_Oreturn tx.litellm_organizationmembership # pyright: ignore[reportReturnType] # TableActions widens the generated inputs to Mapping, as the repositories do+def _same_email(email: str | None, request: MemberDeleteRequest) -> bool:+ return request.user_email is not None and request.user_email == email++def _addresses_member(member: Member, request: MemberDeleteRequest) -> bool:- return (request.user_id is not None and request.user_id == member.user_id) or (- request.user_email is not None and request.user_email == member.user_email- )+ if request.user_id is None:+ return _same_email(member.user_email, request)+ return request.user_id == member.user_id or (member.user_id is None and _same_email(member.user_email, request))def _addresses_user(user: "prisma_models.LiteLLM_UserTable", request: MemberDeleteRequest) -> bool:- return (request.user_id is not None and request.user_id == user.user_id) or (- request.user_email is not None and request.user_email == user.user_email- )+ if request.user_id is None:+ return _same_email(user.user_email, request)+ return request.user_id == user.user_iddef _error_message(exc: BaseException) -> str:@@ -395,7 +399,11 @@ async def _delete_users_tx(prisma_client,tx,tid,- tuple(MemberDeleteRequest(user_id=u.user_id) for u in users if tid in teams_of[u.user_id]),+ tuple(+ MemberDeleteRequest(user_id=u.user_id, user_email=u.user_email)+ for u in users+ if tid in teams_of[u.user_id]+ ),user_api_key_dict,)for tid in team_idsdiff --git a/tests/test_litellm/proxy/management_helpers/test_bulk_user_deletion.py b/tests/test_litellm/proxy/management_helpers/test_bulk_user_deletion.pyindex aac30184e1d..49aed00177a 100644--- a/tests/test_litellm/proxy/management_helpers/test_bulk_user_deletion.py+++ b/tests/test_litellm/proxy/management_helpers/test_bulk_user_deletion.py@@ -308,6 +308,24 @@ async def test_bulk_delete_leaves_teammates_who_share_the_deleted_users_email_alassert [t["token"] for t in prisma.db.litellm_verificationtoken.rows] == ["k-twin"]+async def test_bulk_delete_removes_the_deleted_users_email_only_roster_entry():+ team = LiteLLM_TeamTable(+ team_id="t1",+ members_with_roles=[+ Member(user_id=None, user_email="[email protected]", role="user"),+ Member(user_id="keep", user_email="[email protected]", role="user"),+ ],+ )+ prisma = _FakePrisma(users=[_user("u1", "t1"), _user("keep", "t1")], teams=[team])++ response = await _delete(prisma, ["u1"])++ assert [(r.success, r.teams_removed) for r in response.results] == [(True, ("t1",))]+ assert _roster(prisma, "t1") == ["keep"]+ assert set(prisma.db.litellm_usertable.rows) == {"keep"}++@pytest.mark.asyncioasync def test_bulk_delete_finds_teams_through_membership_rows_when_user_teams_array_is_stale():prisma = _FakePrisma(