From f52fe547fba8c290ae377fc962fce24092515ff1 Mon Sep 17 00:00:00 2001 From: moe-berri Date: Sun, 8 Nov 2026 15:36:27 +0800 Subject: [PATCH] fix(alerts): keep unsupported model names out of search pages --- litellm/repositories/usage_alerts.py | 2 +- tests/integration/database/test_usage_alerts.py | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/litellm/repositories/usage_alerts.py b/litellm/repositories/usage_alerts.py index 6f38af2a862..9380dd86f44 100644 --- a/litellm/repositories/usage_alerts.py +++ b/litellm/repositories/usage_alerts.py @@ -500,7 +500,7 @@ class UsageAlertsRepository: rows: Final = TypeAdapter(tuple[_ModelIdentity, ...]).validate_python( await self.database.query_raw( """SELECT DISTINCT model FROM "LiteLLM_DailyUserSpend" - WHERE date >= $1 AND date <= $2 AND model IS NOT NULL AND model <> '' + WHERE date >= $1 AND date <= $2 AND model IS NOT NULL AND length(model) BETWEEN 1 AND 1024 AND ($3::text IS NULL OR strpos(lower(model),lower($3))>0) AND ($4::text IS NULL OR model>$4) ORDER BY model LIMIT $5""", diff --git a/tests/integration/database/test_usage_alerts.py b/tests/integration/database/test_usage_alerts.py index 29dc17b859e..5ebe5808014 100644 --- a/tests/integration/database/test_usage_alerts.py +++ b/tests/integration/database/test_usage_alerts.py @@ -682,9 +682,14 @@ async def test_reported_model_search_preserves_exact_identity_and_cursor( prefix: Final = f"reported-{uuid4().hex}" initial: Final = await repository.list_reported_models(prefix, None, 1) assert initial.data == () - models: Final = (f"{prefix}/first", f"{prefix}/literal%quote'", f"{prefix}/second") + models: Final = ( + f"{prefix}/first", + f"{prefix}/literal%quote'", + f"{prefix}/second", + prefix + "/z" + "x" * (1022 - len(prefix)), + ) try: - for index, model in enumerate((*models, models[0])): + for index, model in enumerate((*models, models[0], prefix + "/aaa" + "x" * 1025)): await db.prisma.writer_db.execute_raw( 'INSERT INTO "LiteLLM_DailyUserSpend" (id,date,api_key,model,updated_at) VALUES ($1,$2,$3,$4,CURRENT_TIMESTAMP)', f"{prefix}-{index}", @@ -706,7 +711,9 @@ async def test_reported_model_search_preserves_exact_identity_and_cursor( second: Final = await repository.list_reported_models(prefix, first.next_cursor, 1) third: Final = await repository.list_reported_models(prefix, second.next_cursor, 1) assert second.data[0].scope_id == models[1] and third.data[0].scope_id == models[2] - assert third.next_cursor is None + fourth: Final = await repository.list_reported_models(prefix, third.next_cursor, 1) + assert fourth.data[0].scope_id == models[3] and len(fourth.data[0].scope_id) == 1024 + assert fourth.next_cursor is None literal: Final = await repository.list_reported_models(f"{prefix}/literal%quote'", None, 20) assert tuple(option.scope_id for option in literal.data) == (models[1],) assert literal.data[0].label == models[1]