Fix cursor pagination across nullable order values - #970
HarshMN2345 wants to merge 1 commit into
Conversation
|
Warning Review limit reachedNext included review available in 59 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
| @@ -8704,17 +8703,6 @@ public function find(string $collection, array $queries = [], string $forPermiss | |||
| } | |||
There was a problem hiding this comment.
Removing this validation also accepts partial cursor documents that omit required order attributes. Cursor validation checks only the document ID, so a caller can provide a cursor with the correct collection and ID but without the ordered field. The SQL and MongoDB adapters then treat the missing value as null and paginate from the null partition instead of the referenced document's actual position, returning the wrong page rather than rejecting the malformed cursor. Please continue allowing genuinely nullable values while rejecting absent required order fields.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Database/Database.php
Line: 8703
Comment:
**Partial cursors become null**
Removing this validation also accepts partial cursor documents that omit required order attributes. Cursor validation checks only the document ID, so a caller can provide a cursor with the correct collection and ID but without the ordered field. The SQL and MongoDB adapters then treat the missing value as null and paginate from the null partition instead of the referenced document's actual position, returning the wrong page rather than rejecting the malformed cursor. Please continue allowing genuinely nullable values while rejecting absent required order fields.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Cursor pagination drops rows whose ordered value is null because ordinary comparisons never match SQL NULL values. Starting the next page from a null-valued row also raises an order exception. For example, descending values
[4, 2, 1, null]should return[1, null]after the row containing2.Build null-aware cursor comparisons and equality prefixes for SQL and MongoDB, preserve each adapter’s native null ordering, and allow nullable cursor values through the database layer. Compound ordering and both cursor directions retain the existing sequence tie-breaker.
The shared adapter regression covers nullable primary and secondary sort keys, ascending and descending order, cursor-before and cursor-after at every row, and repeated two-row pages. It fails against the current implementation and passes locally with SQLite and Memory (two tests, 256 assertions). Changed-file syntax and Pint checks pass; PHPStan level 7 reports no new diagnostics compared with the unchanged base. GitHub CI passes on this head: all 16 adapter suites, unit tests, Pint, and CodeQL. The PostgreSQL, MongoDB, and Mirror job logs confirm the new cursor regression executed.
Fixes appwrite/appwrite#7083.