Add tag activity database guard

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>
This commit is contained in:
oss-agent-shin 2026-05-06 22:39:08 +00:00
parent e600f02d2d
commit 4b75230222
No known key found for this signature in database
2 changed files with 30 additions and 0 deletions

View file

@ -640,6 +640,9 @@ async def get_tag_daily_activity(
"""
from litellm.proxy.proxy_server import prisma_client
if prisma_client is None:
raise HTTPException(status_code=500, detail="Database not connected")
# Convert comma-separated tags string to list if provided
tag_list = tags.split(",") if tags else None
scoped_api_key_filter = await _get_tag_daily_activity_api_key_filter(

View file

@ -645,6 +645,33 @@ async def test_internal_user_tag_daily_activity_without_any_scoped_keys_returns_
mock_get_daily_activity.assert_not_awaited()
@pytest.mark.asyncio
async def test_get_tag_daily_activity_requires_database_connection():
"""
Tag daily activity should fail with the same explicit DB error used by other
tag endpoints instead of raising an AttributeError during scope resolution.
"""
from litellm.proxy.management_endpoints.tag_management_endpoints import (
get_tag_daily_activity,
)
mock_user_auth = UserAPIKeyAuth(
user_id="internal-user-123",
user_role=LitellmUserRoles.INTERNAL_USER,
)
with patch("litellm.proxy.proxy_server.prisma_client", None):
with pytest.raises(HTTPException) as exc_info:
await get_tag_daily_activity(
start_date="2025-01-01",
end_date="2025-01-31",
user_api_key_dict=mock_user_auth,
)
assert exc_info.value.status_code == 500
assert exc_info.value.detail == "Database not connected"
@pytest.mark.asyncio
async def test_get_deployments_by_model_id():
"""