-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Revert "[Fix] Team Usage Spend Truncated Due to Pagination" #23028
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -77,8 +77,8 @@ | |
| _upsert_budget_and_membership, | ||
| _user_has_admin_view, | ||
| ) | ||
| from litellm.proxy.management_endpoints.common_daily_activity import ( | ||
| get_daily_activity_aggregated, | ||
| from litellm.proxy.management_endpoints.tag_management_endpoints import ( | ||
| get_daily_activity, | ||
| ) | ||
| from litellm.proxy.management_helpers.object_permission_utils import ( | ||
| _set_object_permission, | ||
|
|
@@ -3890,27 +3890,22 @@ async def get_team_daily_activity( | |
| page: int = 1, | ||
| page_size: int = 10, | ||
| exclude_team_ids: Optional[str] = None, | ||
| timezone: Optional[int] = None, | ||
| user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth), | ||
| ): | ||
| """ | ||
| Get daily activity for specific teams or all teams. | ||
|
|
||
| Uses SQL GROUP BY to aggregate all matching rows without pagination, | ||
| ensuring accurate total spend regardless of data volume. | ||
|
|
||
| Args: | ||
| team_ids (Optional[str]): Comma-separated list of team IDs to filter by. If not provided, returns data for all teams. | ||
| start_date (Optional[str]): Start date for the activity period (YYYY-MM-DD). | ||
| end_date (Optional[str]): End date for the activity period (YYYY-MM-DD). | ||
| model (Optional[str]): Filter by model name. | ||
| api_key (Optional[str]): Filter by API key. | ||
| page (int): Deprecated, kept for backward compatibility. All results are returned in a single page. | ||
| page_size (int): Deprecated, kept for backward compatibility. | ||
| page (int): Page number for pagination. | ||
| page_size (int): Number of items per page. | ||
| exclude_team_ids (Optional[str]): Comma-separated list of team IDs to exclude. | ||
| timezone (Optional[int]): Timezone offset in minutes from UTC (e.g., 480 for PST). | ||
| Returns: | ||
| SpendAnalyticsPaginatedResponse: Response containing daily activity data with per-team breakdown. | ||
| SpendAnalyticsPaginatedResponse: Paginated response containing daily activity data. | ||
| """ | ||
| from litellm.proxy.proxy_server import ( | ||
| prisma_client, | ||
|
|
@@ -4014,17 +4009,17 @@ async def get_team_daily_activity( | |
| if final_api_key_filter is None and user_api_keys is not None: | ||
| final_api_key_filter = user_api_keys | ||
|
|
||
| return await get_daily_activity_aggregated( | ||
| return await get_daily_activity( | ||
| prisma_client=prisma_client, | ||
| table_name="litellm_dailyteamspend", | ||
| entity_id_field="team_id", | ||
| entity_id=team_ids_list, | ||
| entity_metadata_field=team_alias_metadata, | ||
| exclude_entity_ids=exclude_team_ids_list, | ||
| start_date=start_date, | ||
| end_date=end_date, | ||
| model=model, | ||
| api_key=final_api_key_filter, | ||
| exclude_entity_ids=exclude_team_ids_list, | ||
| timezone_offset_minutes=timezone, | ||
| include_entity_breakdown=True, | ||
| page=page, | ||
| page_size=page_size, | ||
| ) | ||
|
Comment on lines
+4012
to
4025
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pagination truncation bug reintroduced This revert switches For teams with hundreds or thousands of rows in The correct approach is to use # Before revert (correct):
return await get_daily_activity_aggregated(
...
include_entity_breakdown=True,
)
# After revert (buggy — totals only reflect current page):
return await get_daily_activity(
...
page=page,
page_size=page_size,
) |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
get_daily_activity_aggregatedloses all entity breakdown capabilityAfter this revert,
_aggregate_spend_recordsis always called withentity_id_field=Noneandentity_metadata_field=None, unconditionally. This meansget_daily_activity_aggregatedcan never produce per-entity (per-team, per-user, per-org) spend breakdowns — even if a caller explicitly wants them.The
include_entity_breakdownparameter that controlled this was removed, and the function is now equivalent to the version before PR #22938 except that the SQL still correctly aggregates without the entity dimension inGROUP BY. Any future callers expecting entity-level breakdown from this function will silently get a flat aggregation instead.If this revert is intentional as a short-term rollback, the entity breakdown capability should be restored before the next release.