diff --git a/litellm/proxy/_experimental/out/onboarding.html b/litellm/proxy/_experimental/out/onboarding.html deleted file mode 100644 index 0481f1194ae..00000000000 --- a/litellm/proxy/_experimental/out/onboarding.html +++ /dev/null @@ -1 +0,0 @@ -LiteLLM Dashboard \ No newline at end of file diff --git a/litellm/proxy/auth/auth_checks.py b/litellm/proxy/auth/auth_checks.py index 653455b2886..ede3624da61 100644 --- a/litellm/proxy/auth/auth_checks.py +++ b/litellm/proxy/auth/auth_checks.py @@ -644,6 +644,7 @@ async def get_user_object( proxy_logging_obj: Optional[ProxyLogging] = None, sso_user_id: Optional[str] = None, user_email: Optional[str] = None, + check_db_only: Optional[bool] = None, ) -> Optional[LiteLLM_UserTable]: """ - Check if user id in proxy User Table @@ -655,12 +656,13 @@ async def get_user_object( return None # check if in cache - cached_user_obj = await user_api_key_cache.async_get_cache(key=user_id) - if cached_user_obj is not None: - if isinstance(cached_user_obj, dict): - return LiteLLM_UserTable(**cached_user_obj) - elif isinstance(cached_user_obj, LiteLLM_UserTable): - return cached_user_obj + if not check_db_only: + cached_user_obj = await user_api_key_cache.async_get_cache(key=user_id) + if cached_user_obj is not None: + if isinstance(cached_user_obj, dict): + return LiteLLM_UserTable(**cached_user_obj) + elif isinstance(cached_user_obj, LiteLLM_UserTable): + return cached_user_obj # else, check db if prisma_client is None: raise Exception("No db connected") diff --git a/litellm/proxy/management_endpoints/common_daily_activity.py b/litellm/proxy/management_endpoints/common_daily_activity.py index 90f66a6eb8a..d782adf85cb 100644 --- a/litellm/proxy/management_endpoints/common_daily_activity.py +++ b/litellm/proxy/management_endpoints/common_daily_activity.py @@ -154,7 +154,7 @@ async def get_daily_activity( where_conditions["model"] = model if api_key: where_conditions["api_key"] = api_key - if entity_id: + if entity_id is not None: if isinstance(entity_id, list): where_conditions[entity_id_field] = {"in": entity_id} else: diff --git a/litellm/proxy/management_endpoints/team_endpoints.py b/litellm/proxy/management_endpoints/team_endpoints.py index 1f23a5401c6..cd4ae97ac70 100644 --- a/litellm/proxy/management_endpoints/team_endpoints.py +++ b/litellm/proxy/management_endpoints/team_endpoints.py @@ -2149,6 +2149,7 @@ async def get_team_daily_activity( user_api_key_cache=user_api_key_cache, parent_otel_span=user_api_key_dict.parent_otel_span, proxy_logging_obj=proxy_logging_obj, + check_db_only=True, ) if user_info is None: raise HTTPException( @@ -2157,6 +2158,7 @@ async def get_team_daily_activity( "error": "User= {} not found".format(user_api_key_dict.user_id) }, ) + if team_ids_list is None: team_ids_list = user_info.teams else: diff --git a/tests/litellm/proxy/management_endpoints/test_common_daily_activity.py b/tests/litellm/proxy/management_endpoints/test_common_daily_activity.py new file mode 100644 index 00000000000..ffaed2d88fa --- /dev/null +++ b/tests/litellm/proxy/management_endpoints/test_common_daily_activity.py @@ -0,0 +1,58 @@ +import json +import os +import sys +from datetime import datetime, timezone +from unittest.mock import AsyncMock, MagicMock + +import pytest +from fastapi.testclient import TestClient + +sys.path.insert( + 0, os.path.abspath("../../../..") +) # Adds the parent directory to the system path + +from litellm.proxy.management_endpoints.common_daily_activity import get_daily_activity +from litellm.proxy.proxy_server import app + +client = TestClient(app) + + +@pytest.mark.asyncio +async def test_get_daily_activity_empty_entity_id_list(): + # Mock PrismaClient + mock_prisma = MagicMock() + mock_prisma.db = MagicMock() + + # Mock the table methods + mock_table = MagicMock() + mock_table.count = AsyncMock(return_value=0) + mock_table.find_many = AsyncMock(return_value=[]) + mock_prisma.db.litellm_verificationtoken = MagicMock() + mock_prisma.db.litellm_verificationtoken.find_many = AsyncMock(return_value=[]) + + # Set the table name dynamically + mock_prisma.db.litellm_dailyspend = mock_table + + # Call the function with empty entity_id list + result = await get_daily_activity( + prisma_client=mock_prisma, + table_name="litellm_dailyspend", + entity_id_field="team_id", + entity_id=[], + entity_metadata_field=None, + start_date="2024-01-01", + end_date="2024-01-02", + model=None, + api_key=None, + page=1, + page_size=10, + ) + + # Verify the where conditions were set correctly + mock_table.find_many.assert_called_once() + call_args = mock_table.find_many.call_args[1] + where_conditions = call_args["where"] + + # Check that team_id is set to empty list + assert "team_id" in where_conditions + assert where_conditions["team_id"] == {"in": []}