mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-19 04:54:37 +00:00
fix(proxy): apply default_team_params.models on team creation
new_team applied default_team_params only for fields whose request default is None (max_budget, tpm_limit, etc.). The models field defaults to an empty list, so it was never covered by the None-guard loop and default_team_params.models was silently dropped for teams created via API/SCIM/UI (it only worked on the SSO path). Add a dedicated check that applies the configured default when the request specifies no models. Fixes #30478
This commit is contained in:
parent
343e453c2a
commit
301459adf7
2 changed files with 62 additions and 0 deletions
|
|
@ -1043,6 +1043,14 @@ async def new_team( # noqa: PLR0915
|
|||
if default_value is not None:
|
||||
setattr(data, field, default_value)
|
||||
|
||||
# `models` defaults to an empty list rather than None on the request, so it
|
||||
# needs its own check: apply the configured default when the request did not
|
||||
# specify any models (matches SSO-provisioned team behavior).
|
||||
if not getattr(data, "models", None):
|
||||
default_models = _get_default_team_param("models")
|
||||
if default_models is not None:
|
||||
data.models = default_models
|
||||
|
||||
# Legacy fallback: apply max_budget from default_team_settings (YAML config)
|
||||
# if still not set after checking default_team_params.
|
||||
if data.max_budget is None:
|
||||
|
|
|
|||
|
|
@ -288,6 +288,60 @@ class TestNewTeamDefaultParamsApplied:
|
|||
assert data.tpm_limit == 200 # default applied
|
||||
assert data.rpm_limit == 500 # default applied
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_models_default_applied_when_not_provided(self, monkeypatch):
|
||||
"""default_team_params.models applies to teams created without models (#30478).
|
||||
|
||||
`models` defaults to an empty list rather than None, so it is not covered
|
||||
by the None-guard loop and needs its own handling.
|
||||
"""
|
||||
from litellm.proxy.management_endpoints.team_endpoints import new_team
|
||||
|
||||
monkeypatch.setattr(
|
||||
litellm,
|
||||
"default_team_params",
|
||||
{"models": ["gpt-4", "gpt-3.5-turbo"]},
|
||||
)
|
||||
|
||||
data = NewTeamRequest(team_alias="my-team") # models defaults to []
|
||||
auth = self._make_admin_auth()
|
||||
|
||||
try:
|
||||
await new_team(
|
||||
data=data,
|
||||
user_api_key_dict=auth,
|
||||
http_request=MagicMock(),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
assert data.models == ["gpt-4", "gpt-3.5-turbo"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_models_explicit_not_overridden(self, monkeypatch):
|
||||
"""Explicit models on the request are not overridden by the default."""
|
||||
from litellm.proxy.management_endpoints.team_endpoints import new_team
|
||||
|
||||
monkeypatch.setattr(
|
||||
litellm,
|
||||
"default_team_params",
|
||||
{"models": ["gpt-4"]},
|
||||
)
|
||||
|
||||
data = NewTeamRequest(team_alias="my-team", models=["claude-3-5-sonnet"])
|
||||
auth = self._make_admin_auth()
|
||||
|
||||
try:
|
||||
await new_team(
|
||||
data=data,
|
||||
user_api_key_dict=auth,
|
||||
http_request=MagicMock(),
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
assert data.models == ["claude-3-5-sonnet"]
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_no_defaults_when_config_is_none(self, monkeypatch):
|
||||
"""When default_team_params is None, no defaults applied."""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue