mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-26 03:04:13 +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,
|
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,12 +656,13 @@ async def get_user_object(
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# check if in cache
|
# check if in cache
|
||||||
cached_user_obj = await user_api_key_cache.async_get_cache(key=user_id)
|
if not check_db_only:
|
||||||
if cached_user_obj is not None:
|
cached_user_obj = await user_api_key_cache.async_get_cache(key=user_id)
|
||||||
if isinstance(cached_user_obj, dict):
|
if cached_user_obj is not None:
|
||||||
return LiteLLM_UserTable(**cached_user_obj)
|
if isinstance(cached_user_obj, dict):
|
||||||
elif isinstance(cached_user_obj, LiteLLM_UserTable):
|
return LiteLLM_UserTable(**cached_user_obj)
|
||||||
return cached_user_obj
|
elif isinstance(cached_user_obj, LiteLLM_UserTable):
|
||||||
|
return cached_user_obj
|
||||||
# else, check db
|
# else, check db
|
||||||
if prisma_client is None:
|
if prisma_client is None:
|
||||||
raise Exception("No db connected")
|
raise Exception("No db connected")
|
||||||
|
|
|
@ -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:
|
||||||
|
|
|
@ -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:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue