From 1cf191d9ad3a0732126d67b33813625419adafad Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Mon, 9 Mar 2026 22:44:45 -0700 Subject: [PATCH] [Fix] Deduplicate model lists and remove dead assignment Adds dedup to get_key_models and get_team_models to prevent duplicate entries when access group member models overlap with proxy_model_list. Removes dead assignment of all_models in get_team_models. Co-Authored-By: Claude Opus 4.6 --- litellm/proxy/auth/model_checks.py | 8 ++++++-- tests/test_litellm/proxy/auth/test_model_checks.py | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/litellm/proxy/auth/model_checks.py b/litellm/proxy/auth/model_checks.py index 4ca1449208f..ccbc2f01942 100644 --- a/litellm/proxy/auth/model_checks.py +++ b/litellm/proxy/auth/model_checks.py @@ -122,6 +122,9 @@ def get_key_models( include_model_access_groups=include_model_access_groups, ) + # deduplicate while preserving order + all_models = list(dict.fromkeys(all_models)) + verbose_proxy_logger.debug("ALL KEY MODELS - {}".format(len(all_models))) return all_models @@ -148,14 +151,15 @@ def get_team_models( if include_model_access_groups: all_models_set.update(model_access_groups.keys()) - all_models = list(all_models_set) - all_models = _get_models_from_access_groups( model_access_groups=model_access_groups, all_models=list(all_models_set), include_model_access_groups=include_model_access_groups, ) + # deduplicate while preserving order + all_models = list(dict.fromkeys(all_models)) + verbose_proxy_logger.debug("ALL TEAM MODELS - {}".format(len(all_models))) return all_models diff --git a/tests/test_litellm/proxy/auth/test_model_checks.py b/tests/test_litellm/proxy/auth/test_model_checks.py index 739ff25b7d2..2b484bf975b 100644 --- a/tests/test_litellm/proxy/auth/test_model_checks.py +++ b/tests/test_litellm/proxy/auth/test_model_checks.py @@ -43,6 +43,7 @@ def test_get_team_models_all_proxy_models_includes_access_groups(): assert "group-b" in result assert "model1" in result assert "model2" in result + assert len(result) == len(set(result)), "result should have no duplicates" def test_get_team_models_all_proxy_models_without_include_flag(): @@ -94,6 +95,7 @@ def test_get_key_models_all_proxy_models_includes_access_groups(): assert "group-a" in result assert "model1" in result assert "model2" in result + assert len(result) == len(set(result)), "result should have no duplicates" def test_get_key_models_passes_include_model_access_groups():