litellm - ✅(Solved) Fix [Bug]: Cannot delete user who created pending invitation links (FK constraint violation) [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
BerriAI/litellm#23114Fetched 2026-04-08 00:38:32
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
labeled ×2closed ×1commented ×1cross-referenced ×1

Error Message

  1. Deletion fails with a database FK constraint error

Root Cause

Root Cause:

Fix Action

Fixed

PR fix notes

PR #23115: fix fkey violation on deleting user in Internal Users Section

Description (problem / solution / changelog)

Relevant issues

Fixes #23114

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have Added testing in the tests/test_litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem
  • I have requested a Greptile review by commenting @greptileai and received a Confidence Score of at least 4/5 before requesting a maintainer review

CI (LiteLLM team)

CI status guideline:

  • 50-55 passing tests: main is stable with minor issues.
  • 45-49 passing tests: acceptable but needs attention
  • <= 40 passing tests: unstable; be careful with your merges and assess the risk.
  • Branch creation CI run
    Link:

  • CI run for the last commit
    Link:

  • Merge / cherry-pick CI run
    Links:

Type

🐛 Bug Fix

Changes

  • Fix delete_user endpoint to clean up invitation links where the deleted user is the creator (created_by) or updater (updated_by), not just the invited person (user_id)
  • Uses a single OR query to cover all three FK relations on LiteLLM_InvitationLink
  • Add unit test verifying the OR clause covers all three FK fields

Changed files

  • litellm/proxy/management_endpoints/internal_user_endpoints.py (modified, +7/-1)
  • tests/test_litellm/proxy/management_endpoints/test_internal_user_endpoints.py (modified, +86/-1)
RAW_BUFFERClick to expand / collapse

Check for existing issues

  • I have searched the existing issues and checked that my issue is not a duplicate.

What happened?

When an admin (Person A) creates an invitation link for another user (Person B) via the UI, and Person B has not yet accepted the invite, attempting to delete Person A from the
Internal Users page fails with a foreign key constraint violation.

Root Cause:

The delete_user endpoint in internal_user_endpoints.py only deletes invitation links where the user is the invited person (user_id), but does not clean up links where the user is the creator (created_by) or updater (updated_by).

The LiteLLM_InvitationLink table has three FK relations to LiteLLM_UserTable.user_id:

  • user_id → @relation("UserId")
  • created_by → @relation("CreatedBy")
  • updated_by → @relation("UpdatedBy")

Expected Behaviour: Deleting a user should succeed and also remove any invitation links they created or updated.

Steps to Reproduce

  1. As Admin A, create an invitation link for User B
  2. Do NOT accept the invite as User B (leave it pending)
  3. Try to delete Admin A from the Internal Users page (/user/delete endpoint)
  4. Deletion fails with a database FK constraint error

Relevant log output

What part of LiteLLM is this about?

Proxy

What LiteLLM version are you on ?

v1.82.1

Twitter / LinkedIn details

No response

extent analysis

Fix Plan

To resolve the foreign key constraint violation issue, we need to update the delete_user endpoint to clean up invitation links where the user is the creator or updater.

Here are the steps:

  • Update the delete_user function in internal_user_endpoints.py to include the following:
    • Delete invitation links where the user is the creator (created_by)
    • Delete invitation links where the user is the updater (updated_by)
  • Use the following example code snippet to achieve this:
from sqlalchemy import delete
from LiteLLM_InvitationLink import LiteLLM_InvitationLink

# ...

def delete_user(user_id):
    # ... existing code ...

    # Delete invitation links where the user is the creator or updater
    delete_links = delete(LiteLLM_InvitationLink).where(
        LiteLLM_InvitationLink.created_by == user_id
        | LiteLLM_InvitationLink.updated_by == user_id
    )
    session.execute(delete_links)

    # ... existing code ...

Verification

To verify that the fix worked, follow these steps:

  • Create an invitation link as Admin A for User B
  • Do not accept the invite as User B (leave it pending)
  • Try to delete Admin A from the Internal Users page
  • The deletion should succeed without any foreign key constraint errors

Extra Tips

  • Make sure to test the updated delete_user function thoroughly to ensure it works as expected
  • Consider adding additional logging or error handling to handle any potential issues that may arise during the deletion process

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING