Skip to content

Fix cursor pagination across nullable order values - #970

Open
HarshMN2345 wants to merge 1 commit into
mainfrom
codex/fix-null-cursor-rows
Open

HarshMN2345 wants to merge 1 commit into
mainfrom
codex/fix-null-cursor-rows

Conversation

@HarshMN2345

@HarshMN2345 HarshMN2345 commented Sep 14, 2026

Copy link
Copy Markdown
Member

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 containing 2.

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.

@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 0db189ba-85e5-4949-99d3-40cfe3446036

📥 Commits

Reviewing files that changed from the base of the PR and between 64f5257 and ab95794.

📒 Files selected for processing (5)
  • src/Database/Adapter/Mongo.php
  • src/Database/Adapter/Postgres.php
  • src/Database/Adapter/SQL.php
  • src/Database/Database.php
  • tests/e2e/Adapter/Scopes/DocumentTests.php

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@HarshMN2345
HarshMN2345 marked this pull request as ready for review September 14, 2026 12:31
@greptile-apps

greptile-apps Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

The PR should not merge until partial cursors missing required order attributes are distinguished from legitimate nullable values.

Fix All in Claude CodeFindings

  1. P1 Partial cursors become null
Fix with agent prompt
### Issue 1
src/Database/Database.php:8703
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.

Summary

  • Adds null-aware lexicographic cursor predicates for SQL and MongoDB.
  • Defines PostgreSQL’s differing native null-order direction.
  • Allows nullable ordered values through the database cursor layer.
  • Adds cross-adapter coverage for nullable primary and compound order keys, both cursor directions, and repeated paging.

Reviews (1) · Last reviewed commit: "Fix cursor pagination across nullable or..."

Comment thread src/Database/Database.php
@@ -8704,17 +8703,6 @@ public function find(string $collection, array $queries = [], string $forPermiss
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 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.

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.

Fix in Claude Code Fix in Codex

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.

🐛 Bug Report: Query order desc not include null values

1 participant