mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-07 02:59:05 +00:00
fix(auth): pass a json-serializable where clause to the team alias lookup
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
9bd43ca125
commit
c221884a5c
2 changed files with 30 additions and 2 deletions
|
|
@ -2461,8 +2461,9 @@ async def get_team_model_aliases(
|
|||
if cached is not None:
|
||||
return _TEAM_MODEL_ALIASES_ADAPTER.validate_python(cached)
|
||||
|
||||
where: Final[Mapping[str, object]] = MappingProxyType({"id": model_id})
|
||||
row: Final = await _model_aliases_table(ModelTableRepository(prisma_client)).find_unique(where=where)
|
||||
row: Final = await _model_aliases_table(ModelTableRepository(prisma_client)).find_unique(
|
||||
where={"id": model_id} # mutable-ok: prisma json-serializes query args, and a mappingproxy is not serializable
|
||||
)
|
||||
if row is None or row.model_aliases is None:
|
||||
return None
|
||||
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ from litellm.proxy.auth.auth_checks import (
|
|||
_virtual_key_max_budget_check,
|
||||
_virtual_key_soft_budget_check,
|
||||
get_key_object,
|
||||
get_team_model_aliases,
|
||||
get_team_model_aliases_for_team,
|
||||
get_user_object,
|
||||
vector_store_access_check,
|
||||
|
|
@ -1356,6 +1357,32 @@ async def test_get_team_model_aliases_for_team_guards_incomplete_context_and_del
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_get_team_model_aliases_passes_json_serializable_query_args():
|
||||
"""Prisma json-serializes query args, so a non-dict mapping makes every JWT request fail auth."""
|
||||
|
||||
class _JsonSerializingModelTable:
|
||||
def __init__(self):
|
||||
self.serialized_where = None
|
||||
|
||||
async def find_unique(self, *, where, include=None):
|
||||
self.serialized_where = json.dumps(where)
|
||||
return SimpleNamespace(model_aliases={"claude-opus-4-8": "anthropic-haiku-4-5"})
|
||||
|
||||
model_table = _JsonSerializingModelTable()
|
||||
prisma_client = MagicMock()
|
||||
prisma_client.db.litellm_modeltable = model_table
|
||||
|
||||
aliases = await get_team_model_aliases(
|
||||
model_id=11,
|
||||
prisma_client=prisma_client,
|
||||
user_api_key_cache=UserApiKeyCache(),
|
||||
)
|
||||
|
||||
assert aliases == {"claude-opus-4-8": "anthropic-haiku-4-5"}
|
||||
assert json.loads(model_table.serialized_where) == {"id": 11}
|
||||
|
||||
|
||||
# Vector Store Auth Check Tests
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue