Skip to content

Fix duplicate teams in list_team endpoint #12142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

colesmcintosh
Copy link
Collaborator

@colesmcintosh colesmcintosh commented Jun 28, 2025

Title

Fix duplicate teams in list_team endpoint

Relevant issues

Addresses review comments from #12082

Pre-Submission checklist

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

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • 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

Type

🐛 Bug Fix

Changes

This PR addresses the review comment from #12082 about duplicate teams in the list_team endpoint.

Fixed duplicate teams in list_team logic

  • Added a set to track team IDs and prevent duplicates when iterating through members_with_roles
  • Previously, if a user appeared multiple times in a team's member list, the team would be added multiple times to the response
  • Added test test_list_team_no_duplicates_in_fallback to verify the fix
  • Refactored the filtering logic into a helper function _filter_teams_by_user to satisfy linting requirements

Important Note on the Second Review Comment

The second review comment from krrishdholakia correctly pointed out that using user.teams as the source of truth (as done in #12082) could cause authorization issues, since other parts of the codebase rely on team.members_with_roles for access checks.

This PR reverts to using only team.members_with_roles as the single source of truth, which maintains consistency with the rest of the codebase. The root cause of any drift between user.teams and team.members_with_roles should be addressed separately by ensuring these fields stay in sync during team member add/remove operations.

Test Results

All team endpoint tests passing:

======================== 20 passed, 1 warning in 16.74s ========================

Technical Details

  • Uses a set() to efficiently track added team IDs and prevent duplicates
  • Maintains the original behavior of using team.members_with_roles as the authoritative source
  • Extracted logic into helper function to reduce statement count in main endpoint function

- Modified config/update endpoint to always merge callbacks instead of overwriting
- Fixed issue where UI-added callbacks would replace config-based callbacks
- Added comprehensive tests for callback merging behavior
- Handles edge cases: empty lists, non-list values, and deduplication

Fixes BerriAI#12118
…en user.teams and team.members_with_roles

- Use set to track team IDs and prevent duplicates when filtering teams
- Check both user.teams and team.members_with_roles to handle data drift
- Add warning logs when data drift is detected between the two sources
- Add comprehensive test coverage for duplicate prevention
- Ensure all teams are returned even if data sources are out of sync
Copy link

vercel bot commented Jun 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 29, 2025 3:31pm

@colesmcintosh colesmcintosh changed the title Fix duplicate teams in list_team and handle data drift Fix duplicate teams in list_team endpoint Jun 28, 2025
- Remove user.teams check as it could cause authorization issues
- Keep team.members_with_roles as the single source of truth
- Maintain duplicate prevention using set
- Address review feedback about not using user.teams for filtering
- Fix mypy type errors in _filter_teams_by_user function
- Support both Member objects and dict representations from database
- Ensures compatibility with different data formats from Prisma
@colesmcintosh colesmcintosh marked this pull request as ready for review June 29, 2025 16:19
@colesmcintosh colesmcintosh deleted the fix/team-list-duplicates-and-consistency branch June 30, 2025 15:18
@colesmcintosh colesmcintosh restored the fix/team-list-duplicates-and-consistency branch June 30, 2025 15:19
@colesmcintosh colesmcintosh reopened this Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant