Skip to content

fix: correct pagination behavior for standard pagination with descending ordering clauses#477

Merged
wschurman merged 1 commit intomainfrom
wschurman/02-26-fix_correct_pagination_behavior_for_standard_pagination_with_descending_ordering_clauses
Feb 27, 2026
Merged

fix: correct pagination behavior for standard pagination with descending ordering clauses#477
wschurman merged 1 commit intomainfrom
wschurman/02-26-fix_correct_pagination_behavior_for_standard_pagination_with_descending_ordering_clauses

Conversation

@wschurman
Copy link
Member

@wschurman wschurman commented Feb 26, 2026

Why

This bug was subtle but important, and can be demonstrated best by looking at the new test case added performs forward pagination with descending order.

The bug was that cursor comparison must be derived from both direction but also ASC/DESC of the order bys.

Example:

obj1(t=1)
obj2(t=2)
obj3(t=3)
obj4(t=4)

> loadPage(first: 2, orderBy: t DESC)
obj4
obj3

> loadPage(first: 2, orderBy: t DESC, after: obj3)

the issue is that the cursor comparison for this second load would be:

(t) > (obj3.t)

which yields only obj4, which is incorrect.

How

The fix is to determine cursor comparator by both the order by direction and the pagination direction, thus making the cursor from the example above:

(t) < (obj3.t)

The second part of this is to require all orderBys to have the same ordering for pagination, otherwise this new assumption breaks since cursor comparison then would be unable to be done with a single comparator. While there are ways we can handle different order by directions, we'd have to not use a cursor which adds a massive amount of complexity.

A small other fix was to set the id tiebreaker column order to the same as the other orders.

Test Plan

Add new test case.

@wschurman wschurman force-pushed the wschurman/02-26-fix_correct_precedence_parentheses_for_sqlfragment_joins branch from fe9288b to fa751d8 Compare February 26, 2026 20:15
@wschurman wschurman force-pushed the wschurman/02-26-fix_correct_pagination_behavior_for_standard_pagination_with_descending_ordering_clauses branch 2 times, most recently from 1bf9024 to 65dfc8e Compare February 26, 2026 21:06
@wschurman wschurman force-pushed the wschurman/02-26-fix_correct_precedence_parentheses_for_sqlfragment_joins branch from fa751d8 to 698b8b1 Compare February 26, 2026 21:06
@wschurman wschurman force-pushed the wschurman/02-26-fix_correct_pagination_behavior_for_standard_pagination_with_descending_ordering_clauses branch 2 times, most recently from 537cd6c to a54fcc3 Compare February 26, 2026 21:34
@wschurman wschurman force-pushed the wschurman/02-26-fix_correct_precedence_parentheses_for_sqlfragment_joins branch 2 times, most recently from 1d51229 to 5cf4f64 Compare February 26, 2026 21:52
@wschurman wschurman force-pushed the wschurman/02-26-fix_correct_pagination_behavior_for_standard_pagination_with_descending_ordering_clauses branch 3 times, most recently from 3d91f94 to 744ae7f Compare February 26, 2026 22:10
@wschurman wschurman force-pushed the wschurman/02-26-fix_correct_precedence_parentheses_for_sqlfragment_joins branch from 5cf4f64 to 724cbbd Compare February 26, 2026 22:10
@wschurman wschurman requested review from ide and quinlanj February 26, 2026 22:23
@wschurman wschurman marked this pull request as ready for review February 26, 2026 22:23
@codecov
Copy link

codecov bot commented Feb 27, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (2c4c649) to head (139816d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main      #477    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files          110       110            
  Lines        16198     16228    +30     
  Branches      1456       878   -578     
==========================================
+ Hits         16198     16228    +30     
Flag Coverage Δ
integration 24.31% <100.00%> (+0.14%) ⬆️
unittest 94.89% <32.87%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Member Author

wschurman commented Feb 27, 2026

Merge activity

  • Feb 27, 2:15 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Feb 27, 2:32 AM UTC: Graphite rebased this pull request as part of a merge.
  • Feb 27, 2:35 AM UTC: @wschurman merged this pull request with Graphite.

@wschurman wschurman changed the base branch from wschurman/02-26-fix_correct_precedence_parentheses_for_sqlfragment_joins to graphite-base/477 February 27, 2026 02:28
@wschurman wschurman changed the base branch from graphite-base/477 to main February 27, 2026 02:31
@wschurman wschurman force-pushed the wschurman/02-26-fix_correct_pagination_behavior_for_standard_pagination_with_descending_ordering_clauses branch from 744ae7f to 139816d Compare February 27, 2026 02:32
@wschurman wschurman merged commit e32c4c2 into main Feb 27, 2026
3 checks passed
@wschurman wschurman deleted the wschurman/02-26-fix_correct_pagination_behavior_for_standard_pagination_with_descending_ordering_clauses branch February 27, 2026 02:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants