mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-25 02:34:29 +00:00
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:
parent
bb13ac45c8
commit
f3297ec2bf
3 changed files with 11 additions and 7 deletions
|
@ -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")
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue