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
This commit is contained in:
Krrish Dholakia 2025-04-19 21:42:35 -07:00
parent bb13ac45c8
commit f3297ec2bf
3 changed files with 11 additions and 7 deletions

View file

@ -644,6 +644,7 @@ async def get_user_object(
proxy_logging_obj: Optional[ProxyLogging] = None, proxy_logging_obj: Optional[ProxyLogging] = None,
sso_user_id: Optional[str] = None, sso_user_id: Optional[str] = None,
user_email: Optional[str] = None, user_email: Optional[str] = None,
check_db_only: Optional[bool] = None,
) -> Optional[LiteLLM_UserTable]: ) -> Optional[LiteLLM_UserTable]:
""" """
- Check if user id in proxy User Table - Check if user id in proxy User Table
@ -655,6 +656,7 @@ async def get_user_object(
return None return None
# check if in cache # check if in cache
if not check_db_only:
cached_user_obj = await user_api_key_cache.async_get_cache(key=user_id) cached_user_obj = await user_api_key_cache.async_get_cache(key=user_id)
if cached_user_obj is not None: if cached_user_obj is not None:
if isinstance(cached_user_obj, dict): if isinstance(cached_user_obj, dict):

View file

@ -154,7 +154,7 @@ async def get_daily_activity(
where_conditions["model"] = model where_conditions["model"] = model
if api_key: if api_key:
where_conditions["api_key"] = api_key where_conditions["api_key"] = api_key
if entity_id: if entity_id is not None:
if isinstance(entity_id, list): if isinstance(entity_id, list):
where_conditions[entity_id_field] = {"in": entity_id} where_conditions[entity_id_field] = {"in": entity_id}
else: else:

View file

@ -2149,6 +2149,7 @@ async def get_team_daily_activity(
user_api_key_cache=user_api_key_cache, user_api_key_cache=user_api_key_cache,
parent_otel_span=user_api_key_dict.parent_otel_span, parent_otel_span=user_api_key_dict.parent_otel_span,
proxy_logging_obj=proxy_logging_obj, proxy_logging_obj=proxy_logging_obj,
check_db_only=True,
) )
if user_info is None: if user_info is None:
raise HTTPException( raise HTTPException(
@ -2157,6 +2158,7 @@ async def get_team_daily_activity(
"error": "User= {} not found".format(user_api_key_dict.user_id) "error": "User= {} not found".format(user_api_key_dict.user_id)
}, },
) )
if team_ids_list is None: if team_ids_list is None:
team_ids_list = user_info.teams team_ids_list = user_info.teams
else: else: