[Fix] Fix tag/list 500 error from invalid Prisma group_by kwargs

Use `min`/`max` instead of `_min`/`_max` for Prisma group_by input
parameters. The underscore-prefixed names are output keys, not input
kwargs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
yuneng-jiang 2026-03-13 21:38:20 -07:00
parent 82cdb5b0fb
commit 4fb71e4a21
2 changed files with 7 additions and 10 deletions

View file

@ -456,11 +456,8 @@ async def list_tags(
dynamic_tag_rows = await prisma_client.db.litellm_dailytagspend.group_by(
by=["tag"],
where={"tag": {"not": None}},
# The old find_many(distinct=...) returned arbitrary timestamps from
# whichever row Prisma happened to pick. MIN/MAX give more meaningful
# values: earliest appearance and most recent activity.
_min={"created_at": True},
_max={"updated_at": True},
min={"created_at": True},
max={"updated_at": True},
)
dynamic_tag_config = [
@ -468,8 +465,8 @@ async def list_tags(
"name": row["tag"],
"description": "This is just a spend tag that was passed dynamically in a request. It does not control any LLM models.",
"models": None,
"created_at": row["_min"]["created_at"].isoformat(),
"updated_at": row["_max"]["updated_at"].isoformat(),
"created_at": row["_min"]["created_at"],
"updated_at": row["_max"]["updated_at"],
}
for row in dynamic_tag_rows
if row["tag"] not in stored_tag_names

View file

@ -282,9 +282,9 @@ async def test_list_tags_with_dynamic_tags():
# Setup dynamic tags via group_by — includes one that overlaps with stored
mock_db.litellm_dailytagspend.group_by = AsyncMock(return_value=[
{"tag": "dynamic-tag-1", "_min": {"created_at": datetime(2025, 2, 1)}, "_max": {"updated_at": datetime(2025, 3, 1)}},
{"tag": "dynamic-tag-2", "_min": {"created_at": datetime(2025, 2, 2)}, "_max": {"updated_at": datetime(2025, 3, 2)}},
{"tag": "stored-tag", "_min": {"created_at": datetime(2025, 1, 1)}, "_max": {"updated_at": datetime(2025, 1, 1)}}, # duplicate, should be excluded
{"tag": "dynamic-tag-1", "_min": {"created_at": "2025-02-01T00:00:00Z"}, "_max": {"updated_at": "2025-03-01T00:00:00Z"}},
{"tag": "dynamic-tag-2", "_min": {"created_at": "2025-02-02T00:00:00Z"}, "_max": {"updated_at": "2025-03-02T00:00:00Z"}},
{"tag": "stored-tag", "_min": {"created_at": "2025-01-01T00:00:00Z"}, "_max": {"updated_at": "2025-01-01T00:00:00Z"}}, # duplicate, should be excluded
])
headers = {"Authorization": "Bearer sk-1234"}