fix(common_daily_activity.py): support empty entity id field (#10175)

* fix(common_daily_activity.py): support empty entity id field

allows returning empty response when user is not admin and does not belong to any team

* test(test_common_daily_activity.py): add unit testing
This commit is contained in:
Krish Dholakia 2025-04-19 22:20:28 -07:00 committed by GitHub
parent 72f6bd3972
commit e0a613f88a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 69 additions and 8 deletions

File diff suppressed because one or more lines are too long

View file

@ -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")

View file

@ -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:

View file

@ -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: