Repository navigation
fix(scim): prune deleted user from teams' members_with_roles - #34180
Conversation
Greptile SummaryThis PR removes deleted SCIM users from team membership data. The main changes are:
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| litellm/proxy/management_endpoints/scim/scim_v2.py | Prunes each matching team membership before deleting the SCIM user and stops deletion when pruning fails |
| tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py | Adds tests for membership cleanup delegation, failure propagation, and stale legacy membership |
Reviews (3): Last reviewed commit: "fix(scim): surface delete_user team-prun..." | Re-trigger Greptile
|
|
Greptile SummaryThis PR updates SCIM user deletion to clean up team membership state. The main changes are:
Confidence Score: 4/5A failed team cleanup can leave a dangling member after the user deletion reports success.
litellm/proxy/management_endpoints/scim/scim_v2.py and its SCIM endpoint test
|
| Filename | Overview |
|---|---|
| litellm/proxy/management_endpoints/scim/scim_v2.py | Adds shared team-membership cleanup to SCIM user deletion, but per-team failures can be suppressed before the user is deleted |
| tests/test_litellm/proxy/management_endpoints/scim/test_scim_v2_endpoints.py | Adds a single-team delegation test without checking the resulting persisted membership state |
Reviews (2): Last reviewed commit: "fix(scim): prune deleted user from teams..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
@greptileai please review the current head 0358d87 |
SCIM delete_user removed the user from the legacy team.members column and deleted
their team membership rows, but never pruned members_with_roles, which is the
source of truth ScimTransformations reads for GET /Groups/{id}. A deleted user
therefore lingered as a dangling member reference on every team they belonged to
Prune each of the user's teams directly via team_member_delete before deleting
the user row, and only for teams whose members_with_roles actually contain the
user, so a real DB failure surfaces (the endpoint fails loudly and the user is
kept; SCIM DELETE is idempotent, so the IdP retries) while a user who was never
in a team's members_with_roles stays a no-op. patch_team_membership is left
unchanged for its other callers
0358d87 to
9e702e8
Compare
Relevant issues
#34162
Linear ticket
Part of LIT-4676
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Independent e2e (Devin): after DELETE /Users the deleted user is pruned from the team's members_with_roles and no longer returned by GET /Groups (parent left the stale member).
SCIM
delete_userused to remove the user from the legacyteam.membersString[] column and delete theirLiteLLM_TeamMembershiprows, but it never prunedmembers_with_roles, which is the source of truthScimTransformations.transform_litellm_team_to_scim_groupreads forGET /Groups/{id}. So a deleted user kept showing up as a dangling member reference on every team they belonged to. The prune now runs before the user row is deleted, throughteam_member_delete, and a genuine prune failure surfaces instead of being swallowed, so we never report a successful delete while leaving a stale member (SCIM DELETE is idempotent, so the IdP retries). This bug lives entirely in the SCIM management path with no LLM inference, so the faithful end-user reproduction is curl against a live proxy plus a direct look at themembers_with_rolescolumn in PostgresLive proxy on
127.0.0.1:4292, backed by a local Postgres, master-key authBefore (bug), captured at commit
2b2ae4ca491278ed9e88227bb166a5c8c3c29279After (fixed), captured at commit
0358d8739fe6e47de2d7030dfafa2b1e260bb10eScenario A, normal delete leaves no dangling member
Scenario B, a prune-path failure surfaces and the user is kept (fault injected by corrupting the team's
members_with_rolesso the prune cannot complete)Type
🐛 Bug Fix
Changes
delete_usernow prunes each of the user's teams before deleting the user row. For every team the user belongs to whosemembers_with_rolesactually contains them, it callsteam_member_delete(with aPROXY_ADMINUserAPIKeyAuth, the same pattern the sibling SCIM group code uses), which keepsmembers_with_roles,user.teams, andLiteLLM_TeamMembershipconsistent, so the source of truthGET /Groups/{id}reads no longer references a deleted user. Teams the user is not a member of are skipped, so a stale legacyteam.membersentry can't turn the delete into an error. The legacyteam.memberscleanup stays because that column is still queried elsewhere (list_team_v2)The prune runs directly rather than through
patch_team_membership, which logs and suppresses everyteam_member_deleteerror. Under that helper a genuine DB failure mid-prune left a dangling member while the endpoint still returned 204. Routing directly lets a real failure propagate through the endpoint's exception handler so it fails loudly and the user row is not deleted; SCIM DELETE is idempotent, so the IdP retries.patch_team_membershipis unchanged for its other callersThree regression tests cover it:
test_delete_user_prunes_members_with_roles(a member is removed viateam_member_deleteand the user is deleted),test_delete_user_surfaces_prune_failure_and_keeps_user(a raised prune error surfaces and the user row is not deleted), andtest_delete_user_skips_teams_where_not_a_member(a user absent frommembers_with_rolesis a no-op and the delete still succeeds). All three fail on the pre-fix behavior and pass with the fixFinal Attestation