Skip to content

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]

fix(proxy): keep a team on a /user/bulk_new row when the roster already lists that user id

ryan0c9e0c407e29
diff --git a/litellm/proxy/management_helpers/bulk_user_creation.py b/litellm/proxy/management_helpers/bulk_user_creation.py
index 8bd7e83d122..2eed5121755 100644
--- a/litellm/proxy/management_helpers/bulk_user_creation.py
+++ b/litellm/proxy/management_helpers/bulk_user_creation.py
@@ -572,7 +572,7 @@ async def _write_team_roster(
return _TeamWrite(
team_id=team.team_id,
after=after,
- added=frozenset(member.user_id for member in new_members),
+ added=frozenset(member.user_id for member in members),
failed=MappingProxyType({}),
)
except Exception as exc: # noqa: BLE001 # the team write failure is reported on each affected row
diff --git a/tests/test_litellm/proxy/management_helpers/test_bulk_user_creation.py b/tests/test_litellm/proxy/management_helpers/test_bulk_user_creation.py
index 00ddd63c057..16e56c1b723 100644
--- a/tests/test_litellm/proxy/management_helpers/test_bulk_user_creation.py
+++ b/tests/test_litellm/proxy/management_helpers/test_bulk_user_creation.py
@@ -220,6 +220,18 @@ async def test_creates_users_and_team_membership_in_every_store():
]
+async def test_user_id_already_on_the_roster_keeps_the_team_and_is_not_added_twice():
+ prisma = _FakePrisma(teams=[_team("t1", [Member(user_id="u1", role="user")])])
+ response = await _run(prisma, [{"user_id": "u1", "teams": ["t1"]}, {"user_id": "u2", "teams": ["t1"]}])
+
+ assert [r.success for r in response.results] == [True, True]
+ assert [r.teams for r in response.results] == [("t1",), ("t1",)]
+ assert [r.error for r in response.results] == [None, None]
+ assert prisma.db.litellm_usertable.rows["u1"].teams == ["t1"]
+ assert [m.user_id for m in prisma.db.litellm_teamtable.rows["t1"].members_with_roles] == ["u1", "u2"]
+
+
@pytest.mark.asyncio
async def test_one_insert_and_one_locked_write_per_team():
prisma = _FakePrisma(teams=[_team("t1"), _team("t2")])