Skip to content

fix(api): Reverse previous-page ordering for descending paginators - #127799

Draft
joshuarli wants to merge 2 commits into
masterfrom
fix/paginator-prev-page-order-by
Draft

joshuarli wants to merge 2 commits into
masterfrom
fix/paginator-prev-page-order-by

Conversation

@joshuarli

@joshuarli joshuarli commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

BasePaginator.build_queryset reverses the queryset ordering when a previous-page cursor needs the opposite direction. In the branch where the queryset is already ordered by -key and ascending order is needed, the result was assigned to queryset.query.order_b, a typo for order_by. The assignment only set a stray attribute, so the queryset stayed descending while the cursor filter was built for ascending order, and the previous page came back with the wrong rows. It now assigns order_by, as the sibling branch above it does.

The only affected callers are paginators whose queryset is already ordered by -key and that are asked for a previous page.

Regression test: test_prev_page_with_explicit_descending_queryset covers an explicitly descending queryset and asserts the preceding page is returned. It fails on the typo and passes with the fix.

BasePaginator.build_queryset assigned the reversed ordering to queryset.query.order_b, a typo for order_by, when the queryset was already ordered by the descending key and a previous-page cursor needed ascending order. The assignment was silently dropped, so the previous page was filtered as if ascending but still sorted descending, returning the wrong rows. The ordering is now written to order_by, matching the sibling branch.
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label Oct 16, 2026
Exercise the branch that reverses an explicitly descending queryset for
a previous-page cursor. Without the order_by fix, the previous page
returns the current row instead of the preceding page.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

GitHub Team: python-typing Scope: Backend Automatically applied to PRs that change backend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant