feat(query): after/before on traversed keys and projections - #403
Merged
Conversation
Position paging works for related-column order keys and projected records from a decoded tuple. position_of still requires populated relations on instances and selected order keys on Row. Co-authored-by: Cursor <cursoragent@cursor.com>
This was referenced Aug 30, 2026
0x054
added a commit
that referenced
this pull request
Aug 30, 2026
## Summary Keyset `after()` / `before()` derived from a query's `order_by`, NULL-placement aware (ADR-0018). A position is the ordered tuple of order-key values; `position_of(row)` reads it; `after(row)` / `before(row)` are sugar. Cursor encoding stays the caller's. - Omitted `nulls=` is `"last"` on every dialect (ADR-0017 — **breaking** vs native PG DESC / SQLite ASC). `"native"` is the explicit escape. - `after(position)` pages forward (exclusive). `None` is legal in every non-PK slot so a pinned-first list can cross into unpinned rows in one query. - `before(position).limit(n)` is the adjacent previous page in declared order; unbounded `before()` is the earlier-row prefix (`first()` and `all()[0]` disagree — documented). - Traversed order keys and projected records page from a tuple (`include()` not required). `position_of` still requires populated relations / selected keys. QueryIR is v14. One Rust expander (`exclusive_stepwise_compare`) owns the compare tree; `before` inverts keys then reuses it. ## Test plan - [x] Slice CI on `feat/position-paging`: #397–#403 (rust, python PR, sqlite+postgres matrix) - [ ] Confirm CI on this PR against `main` - [ ] Smoke: `order_by(pinned_at, "desc").order_by(id).after((None, id))` and `before(pos).limit(n)` Closes #372 Made with [Cursor](https://cursor.com) --------- Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
after/beforenow page when an order key is a related column (order_by(lambda t: t.account.label)) or the query is a projected record. A decoded tuple is enough —include()is not required to page.position_ofon a model instance requires those relations populated (same contract as readingrow.account.label).position_ofon a projectedRowrequires every order key in the projection; otherwise pass a tuple.Changes
_assert_position_order_keys. Root PK must still appear among the order keys (a relatediddoes not count).Nonestays legal in every non-PK slot, including aleft_join'd missing relation.position_of(instance)walks populated__dict__relation hops and errors by path when a hop is unpopulated.ProjectedQuery.position_of(Row)matches order keys by source or output name; missing key tells the caller to pass a tuple.beforeon a path-carrying order key still qualifies throughqualify_column_with_joins(no second expander).Bridge and Schema Impact
src/ferro/_core.pyiupdated (if needed)Python builder/validation only plus a Rust unit pin. QueryIR is unchanged (
ir_versionstays 14). Path-carryingorder_byalready qualified in the walker.Migration / Breaking Changes
Queries that previously raised "traversed order key is not supported yet" now page.
Documentation and Changelog
User-visible
feat— release tooling records the changelog (I-10). Do not hand-editCHANGELOG.md.Related Issues
Test plan
after/beforefrom a tuple (noinclude()),left_join+Nonerelated slot, projected-record paging,position_ofpopulated vs unpopulatedidis not the model PK, expression order keys still fail atorder_by()cargo test --no-default-features --features testing query::(includesbefore_condition_qualifies_path_carrying_order_key)uv run ty check src/ferro/querypytest-postgresqlcannot start locally (pg_ctl initdbfailed). CI will run it.Exit Steps
Made with Cursor