[Refactor] Extract _convert_teams_to_response_models to fix PLR0915

list_team_v2 had 51 statements (limit 50). Extract the team-to-response-model
conversion loop into a helper function to satisfy ruff PLR0915.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
yuneng-jiang
2026-03-18 11:59:44 -07:00
co-authored by Claude Opus 4.6
parent bbabdaab38
commit dcc0c70936
@@ -3323,6 +3323,30 @@ async def _build_team_list_where_conditions(
return where_conditions
def _convert_teams_to_response_models(
teams: list,
use_deleted_table: bool,
) -> List[Union[TeamListItem, LiteLLM_TeamTable, LiteLLM_DeletedTeamTable]]:
"""Convert raw Prisma team rows to response models."""
team_list: List[Union[TeamListItem, LiteLLM_TeamTable, LiteLLM_DeletedTeamTable]] = []
for team in teams:
try:
team_dict = team.model_dump()
except Exception:
team_dict = team.dict()
if use_deleted_table:
team_list.append(LiteLLM_DeletedTeamTable(**team_dict))
else:
members_with_roles = team_dict.get("members_with_roles")
if not isinstance(members_with_roles, list):
members_with_roles = []
team_dict["members_with_roles"] = members_with_roles
members_count = len(members_with_roles)
team_list.append(TeamListItem(**team_dict, members_count=members_count))
return team_list
@router.get(
"/v2/team/list",
tags=["team management"],
@@ -3521,22 +3545,7 @@ async def list_team_v2(
total_pages = -(-total_count // page_size) # Ceiling division
# Convert Prisma models to response models with members_count
team_list: List[Union[TeamListItem, LiteLLM_TeamTable, LiteLLM_DeletedTeamTable]] = []
for team in teams:
try:
team_dict = team.model_dump()
except Exception:
team_dict = team.dict()
if use_deleted_table:
team_list.append(LiteLLM_DeletedTeamTable(**team_dict))
else:
members_with_roles = team_dict.get("members_with_roles")
if not isinstance(members_with_roles, list):
members_with_roles = []
team_dict["members_with_roles"] = members_with_roles
members_count = len(members_with_roles)
team_list.append(TeamListItem(**team_dict, members_count=members_count))
team_list = _convert_teams_to_response_models(teams, use_deleted_table)
return {
"teams": team_list,