Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/sentry/api/paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,8 +295,12 @@ def get_result(
if self.on_results:
results = self.on_results(results)

if count_hits:
hits = self.count_hits(max_hits=MAX_HITS_LIMIT)
if known_hits is not None:
hits = known_hits
elif count_hits:
if max_hits is None:
max_hits = MAX_HITS_LIMIT
hits = self.count_hits(max_hits)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Inconsistent Paginator Hit Counts

When known_hits is provided, it should be capped by max_hits for consistency with SequencePaginator. Currently, OffsetPaginator uses known_hits directly without applying the max_hits bound. If both parameters are provided together, hits could exceed max_hits, creating inconsistent behavior across paginators.

Fix in Cursor Fix in Web

else:
hits = None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,14 @@ def fetch_workflow_groups_paginated(
.annotate(detector_id=Subquery(group_max_dates.values("detector_id")))
)

# Count distinct groups for pagination
group_count = qs.count()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a quick note that this will add another query and may impact performance; i'm guessing we need this to get the total number of results compared to the paginated list though.


return cast(
CursorResult[Group],
OffsetPaginator(
qs,
order_by=("-count", "-last_triggered"),
on_results=convert_results,
).get_result(per_page, cursor, count_hits=True),
).get_result(per_page, cursor, known_hits=group_count),
)
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_pagination(self) -> None:
self.user,
WorkflowGroupHistorySerializer(),
)
assert resp["X-Hits"] == "4"
assert resp["X-Hits"] == "2" # 2 unique groups, not 4 total history records

resp = self.get_success_response(
self.organization.slug,
Expand All @@ -119,7 +119,7 @@ def test_pagination(self) -> None:
self.user,
WorkflowGroupHistorySerializer(),
)
assert resp["X-Hits"] == "4"
assert resp["X-Hits"] == "2" # 2 unique groups, not 4 total history records

def test_invalid_dates_error(self) -> None:
self.get_error_response(
Expand Down
Loading