Skip to content

fix(databases): legacy cursor pages, unknown legacy methods and relationship ordering - #14543

Merged
abnegate merged 6 commits into
mainfrom
qfix-legacy-formats
Oct 15, 2026
Merged

abnegate merged 6 commits into
mainfrom
qfix-legacy-formats

Conversation

@abnegate

Copy link
Copy Markdown
Member

Release blocker for #11649, found by staging QA of appwrite-labs/cloud#5410.

What

Three regressions in the utopia-php/database 8.x migration that main's E2E assertions catch on staging, plus a fourth with the same root cause found while auditing.

  1. Cursor pagination of listDocuments returns 500 for every pre-1.8 SDK. The V20 request filter read select queries through Query::groupByType. In 8.x that throws Invalid cursor: a cursor must be a document, string given, because at request-filter time the cursor is still the ID the action resolves later. The filter now reads selects with Query::getByType($parsed, [Method::Select]), which leaves the cursor alone. This affects formats 1.5 to 1.7 (JSON syntax) and 1.4 (string syntax).
  2. An unknown method in pre-1.5 string syntax leaked a PHP enum class name. bogus("title","x") with format 1.4.0 returned "bogus" is not a valid backing value for enum Utopia\Query\Method. V17 now keeps an unknown method as {"method":"bogus"}, so the endpoint rejects it with Invalid query method: bogus and general_query_invalid, the same path as before 8.x.
  3. Ordering by a relationship with no column returned a misleading 404. Examples are orderAsc("starringActors") on a one-to-many parent, a many-to-one child or either side of a many-to-many. The library's order validator accepts every relationship key, and the engine fails on the unknown column. 8.x maps that to NotFound, which the list action read as a missing collection or table. A new Appwrite\Utopia\Database\Validator\Query\Order checks the order queries against the collection's columnless relationships before anything runs, so the request now gets a 400 general_query_invalid that names the attribute. Main returned 500 here.
  4. Cursor pagination of VCS repository branches called Query::groupByType with a branch-name cursor and hit the same throw. It now reads limit and offset with getByType.

Audit

I checked every groupByType caller in src/ and app/:

  • Every other list action calls it after the cursor is resolved to a document.
  • MockPhone, OAuth2, Policies and email Templates only accept limit and offset.
  • Documents/Get catches the QueryException and returns 400. A cursor on a get request is invalid anyway.
  • TransactionState runs after cursor resolution.
  • No other request filter (V16 to V27) or GraphQL path constructs queries in a way that trips 8.x.

Overlap

#14538 (qfix-errors-blockers) changes how the list action maps a NotFound caused by an unknown column. This PR only adds the validator, which runs before that path, so the two are independent. They merge cleanly in either order (checked with git merge-tree).

Tests

  • Unit tests:
    • V20Test: cursorAfter and cursorBefore IDs pass through, both with and without an explicit select.
    • V17Test: an unknown method is kept for endpoint validation, and a dotted method is still rejected.
    • OrderTest: covers every relationship type and side, plus plain, internal and unknown attributes.
  • E2E:
    • LegacyCustomServerTest: cursor pages for formats 1.7.0 and 1.5.0 (JSON) and 1.4.0 (string syntax), cursorBefore, and the unknown-method message.
    • DatabasesBase: orderAsc and orderDesc on starringActors return 400 (Legacy and TablesDB).
    • VCSGiteaConsoleClientTest: branch cursorAfter and cursorBefore pages.
  • Red before the fix: the new V20 cases fail with Invalid query: Invalid cursor: a cursor must be a document, string given. The new V17 case fails with "bogus" is not a valid backing value for enum Utopia\Query\Method.

🤖 Generated with Claude Code

abnegate and others added 3 commits October 15, 2026 22:46
Two pre-1.8 request filters broke under utopia-php/database 8.x:

- V20 read the select queries through Query::groupByType, which now
  insists a cursor is a resolved document. At request-filter time the
  cursor is still the id the action resolves later, so every cursor
  page of listDocuments from a pre-1.8 SDK answered 500. Read the
  selects with getByType, which does not inspect the cursor.
- V17 built a Query from the method name, and the enum-backed
  constructor throws a ValueError for an unknown method, leaking
  "is not a valid backing value for enum Utopia\Query\Method" to the
  client. Keep an unknown method as {"method": name} so the endpoint
  rejects it with "Invalid query method", as it did before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A one-to-many parent, a many-to-one child and either side of a
many-to-many keep their related ids on the other collection or in a
junction table, so the collection has nothing to sort on. The library's
order validator accepts every relationship key, the engine then fails
on the unknown column, and 8.x surfaces that as NotFound, which the
list action answered as a 404 for the whole collection. Validate the
order queries against the collection's relationship columns first so
the request is a 400 general_query_invalid naming the attribute.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The branches list read limit and offset through Query::groupByType,
which in utopia-php/database 8.x throws when the cursor is not a
document. A branch cursor is a branch name, so every cursorAfter or
cursorBefore page failed. Read limit and offset with getByType instead.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@luxor-code-review

luxor-code-review Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Review complete. 🟠 1 high

💬 Inline comments (1)


The change introduces a new Order query validator wired into the shared Documents XList action, which propagates to TablesDB rows and other document-listing surfaces, rejecting order queries on relationship attributes that have no backing column. VCS repository branch listing and the V17/V20 legacy request filters are refactored from groupByType to getByType extraction with equivalent semantics. Tests cover the validator matrix, legacy filter passthrough behavior, and Gitea branch pagination.

Files Change
src/Appwrite/Utopia/Database/Validator/Query/Order.php New validator rejecting order-by on relationship attributes without a backing column
src/Appwrite/Platform/Modules/Databases/.../Documents/XList.php Wires the Order guard into the shared document-list endpoint
src/Appwrite/Platform/Modules/VCS/.../Branches/XList.php Switches limit/offset/cursor extraction to Query::getByType
src/Appwrite/Utopia/Request/Filters/V17.php, V20.php Refactors legacy query parsing to array returns and getByType extraction
tests/unit/Utopia/.../OrderTest.php, V17Test.php, V20Test.php Unit coverage for the validator and filter matrices
tests/e2e/Services/Databases/*, tests/e2e/Services/VCSGitea/* E2E coverage for relationship ordering rejection and branch cursor pagination

Reviewed commit: 5f62105

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

19 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (12)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR adds a query validator rejecting order-by on columnless relationship attributes for document listings, refactors limit/offset/cursor extraction in VCS branch listing and legacy request filters, and expands unit and e2e coverage.

Key findings

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → qfix-legacy-formats (after).

Metric Before After Change
🚀 Requests/sec 200.86 205.5 ⚪ +2.3%
⏱️ Latency P50 86.52 ms 84.87 ms ⚪ -1.9%
⏱️ Latency P95 202.98 ms 193.87 ms ⚪ -4.5%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 84.87 193.87 12,654 205.5 -9.11
Account 155.55 287.48 666 11.04 -37.02
TablesDB 80.59 143.5 6,882 113.33 -25.35
Storage 83.37 190.5 3,330 57.03 +15.65
Functions 116.61 224.46 1,776 31.23 -5.38

Top API waits (after)

API request Max wait (ms)
account.name.update 428.54
account.prefs.update 360.69
storage.buckets.create 343.76
functions.create 343.14
tablesdb.rows.create 326.77

SDKs send a branch cursor as the plain branch name. Spell that payload
out instead of serialising a Document, so the test reads as the request
real clients make and does not lean on how the library serialises a
document cursor.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ghost

ghost commented Oct 15, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

No actionable issues were found in the new change or the previously reviewed changes.

This pull request preserves legacy cursor query handling, sends unknown legacy methods through normal endpoint validation, and rejects ordering by relationship attributes without local columns. It also fixes branch-list pagination and expands unit and E2E coverage across the affected request formats and endpoints, with the latest test update waiting for newly created branches to appear before testing cursor pages.

Latest changes: The newest commit makes the Gitea branch pagination E2E test poll until all three branches are visible before proceeding with cursor assertions.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 11
File Change
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php Rejects ordering by columnless relationship attributes before listing documents.
src/Appwrite/Platform/Modules/VCS/Http/Installations/Repositories/Branches/XList.php Reads branch pagination limit and offset without grouping unresolved cursor queries.
src/Appwrite/Utopia/Database/Validator/Query/Order.php Validates order queries against relationship attributes without a local column.
src/Appwrite/Utopia/Request/Filters/V17.php Preserves unknown legacy query methods for endpoint validation while rejecting dotted methods.
src/Appwrite/Utopia/Request/Filters/V20.php Reads select queries without grouping unresolved cursor values.
tests/e2e/Services/Databases/DatabasesBase.php Covers rejecting order-by requests for a columnless relationship.
tests/e2e/Services/Databases/LegacyCustomServerTest.php Covers legacy cursor pagination formats and unknown legacy query methods.
tests/e2e/Services/VCSGitea/VCSGiteaConsoleClientTest.php Covers branch cursor pagination and waits for newly created branches to become visible.
tests/unit/Utopia/Database/Validator/Query/OrderTest.php Covers relationship column detection and order-query validation.
tests/unit/Utopia/Request/Filters/V17Test.php Covers unknown method preservation and dotted legacy method rejection.
tests/unit/Utopia/Request/Filters/V20Test.php Covers cursor passthrough with and without explicit selects.

Reviewed the commits since 6522485 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

abnegate and others added 2 commits October 15, 2026 22:58
Gitea answers 201 for a new branch before its branch list includes it, so the
first unfiltered list could see only main on a slow runner (PostgreSQL dedicated
VCSGitea lane got 1 branch, expected 3).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@abnegate
abnegate merged commit 26db78c into main Oct 15, 2026
63 checks passed
@ChiragAgg5k ChiragAgg5k mentioned this pull request Oct 21, 2026
6 tasks
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.

1 participant