fix(team_endpoints.py): ensure 404 raised when team not found (#9038)

* fix(team_endpoints.py): ensure 404 raised when team not found

* fix(key_management_endpoints.py): fix adding tags to key when metadata is empty

* fix(key_management_endpoints.py): refactor set metadata field to use common function across keys + teams

reduces scope for errors + easier testing

* fix: fix linting error
This commit is contained in:
Krish Dholakia 2025-03-06 22:04:36 -08:00 committed by GitHub
parent 6dc83135ab
commit 274147bc5e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 72 additions and 27 deletions

View file

@ -1,4 +1,12 @@
from litellm.proxy._types import LiteLLM_TeamTable, UserAPIKeyAuth
from typing import Any, Union
from litellm.proxy._types import (
GenerateKeyRequest,
LiteLLM_ManagementEndpoint_MetadataFields_Premium,
LiteLLM_TeamTable,
UserAPIKeyAuth,
)
from litellm.proxy.utils import _premium_user_check
def _is_user_team_admin(
@ -12,3 +20,22 @@ def _is_user_team_admin(
return True
return False
def _set_object_metadata_field(
object_data: Union[LiteLLM_TeamTable, GenerateKeyRequest],
field_name: str,
value: Any,
) -> None:
"""
Helper function to set metadata fields that require premium user checks
Args:
object_data: The team data object to modify
field_name: Name of the metadata field to set
value: Value to set for the field
"""
if field_name in LiteLLM_ManagementEndpoint_MetadataFields_Premium:
_premium_user_check()
object_data.metadata = object_data.metadata or {}
object_data.metadata[field_name] = value