diff --git a/litellm/proxy/management_endpoints/model_management_endpoints.py b/litellm/proxy/management_endpoints/model_management_endpoints.py index 1acedfb346..d8a1075a16 100644 --- a/litellm/proxy/management_endpoints/model_management_endpoints.py +++ b/litellm/proxy/management_endpoints/model_management_endpoints.py @@ -499,36 +499,37 @@ async def _update_existing_team_model_assignment( if old_public_name and public_model_name != old_public_name: if prisma_client is None: verbose_proxy_logger.warning( - "prisma_client not initialized; skipping old public name cleanup to preserve sibling deployments" + "prisma_client not initialized; skipping public name update entirely to avoid orphaned entries" ) - else: - response = await prisma_client.db.litellm_proxymodeltable.find_many( - where={ - "model_info": { - "path": ["team_id"], - "equals": team_id, - } - } - ) - if not response: - other_deployments_with_old_name = [] - else: - other_deployments_with_old_name = [ - d - for d in response - if d.model_name != db_model.model_name - and _get_team_public_model_name(d.model_info) == old_public_name - ] + return - if not other_deployments_with_old_name: - await team_model_delete( - data=TeamModelDeleteRequest( - team_id=team_id, - models=[old_public_name], - ), - http_request=Request(scope={"type": "http"}), - user_api_key_dict=user_api_key_dict, - ) + response = await prisma_client.db.litellm_proxymodeltable.find_many( + where={ + "model_info": { + "path": ["team_id"], + "equals": team_id, + } + } + ) + if not response: + other_deployments_with_old_name = [] + else: + other_deployments_with_old_name = [ + d + for d in response + if d.model_name != db_model.model_name + and _get_team_public_model_name(d.model_info) == old_public_name + ] + + if not other_deployments_with_old_name: + await team_model_delete( + data=TeamModelDeleteRequest( + team_id=team_id, + models=[old_public_name], + ), + http_request=Request(scope={"type": "http"}), + user_api_key_dict=user_api_key_dict, + ) await team_model_add( data=TeamModelAddRequest( diff --git a/litellm/router.py b/litellm/router.py index 19a0f250dc..76c13443e7 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -8227,12 +8227,16 @@ class Router: """ if ( team_id is not None - and model["model_info"].get("team_id") == team_id - and model_name == model["model_info"].get("team_public_model_name") + and (model.get("model_info") or {}).get("team_id") == team_id + and model_name + == (model.get("model_info") or {}).get("team_public_model_name") ): return True elif model_name is not None and model["model_name"] == model_name: - if team_id is None or model["model_info"].get("team_id") == team_id: + if ( + team_id is None + or (model.get("model_info") or {}).get("team_id") == team_id + ): return True return False