From dcc0c709365eca246ea16d7ded577728af2c6d52 Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Wed, 18 Mar 2026 11:59:31 -0700 Subject: [PATCH] [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) --- .../management_endpoints/team_endpoints.py | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/litellm/proxy/management_endpoints/team_endpoints.py b/litellm/proxy/management_endpoints/team_endpoints.py index e7cd6c1748..bee4b2517e 100644 --- a/litellm/proxy/management_endpoints/team_endpoints.py +++ b/litellm/proxy/management_endpoints/team_endpoints.py @@ -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,