Skip to content

chore(deps): bump utopia-php/database to 8.3.4 - #14576

Merged
abnegate merged 6 commits into
mainfrom
qfix-bump-database-832
Oct 16, 2026
Merged

abnegate merged 6 commits into
mainfrom
qfix-bump-database-832

Conversation

@abnegate

@abnegate abnegate commented Oct 16, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Bumps utopia-php/database from 8.3.0 to 8.3.4 (root constraint stays ^8.3; the absorbed abuse, audit, migration and usage packages now require ^8.3.4). 8.3.2 fixes nine query bugs QA reported against the API. 8.3.3 and 8.3.4 are the production-incident fixes cloud already runs: a stored index whose attributes 7.x left null (utopia-php/database#1033) and a relationship whose related collection 7.x left deleted (utopia-php/database#1034). Each one now has an API-level E2E test, run on TablesDB rows and legacy documents, as a server key and as a client.

One server change was needed. Since utopia-php/database#1032, a distinct row has no $id unless $id is selected. 8.3.0 gave it a null one, and the response models used that null $id to tell a non-stored row apart. Without it, a distinct row fell through to the stored-record branch: it picked up empty $sequence, $createdAt and $updatedAt, and kept the $databaseId and $tableId/$collectionId that the metadata decorator stamps on every row find() returns. That happened in REST, GraphQL and reads inside a transaction.

Commits

  1. test(databases): the E2E tests on their own, run against main (8.3.0) to show they fail first.

  2. chore(deps): the bump to 8.3.2.

  3. fix(databases): distinct rows are hydrated as Aggregate on every path that lists rows: the read (cache miss), the cache hit and the transaction read. The Row and Document models add no stored attributes to an Aggregate row and drop its location metadata ($databaseId, $tableId/$collectionId). A distinct row now carries only what it selects, including $id when $id is selected.

  4. chore(deps): the bump to 8.3.4.

  5. fix(databases): a distinct read inside a transaction adds staged creates through TransactionState::applyProjection(), which always kept $id, $collection, $createdAt, $updatedAt and $permissions, so those rows carried stored fields the committed distinct rows lacked. A distinct projection now keeps only the selected attributes. (Found in review.)

The 8.3.3 and 8.3.4 incident fixes

These have no server-ce E2E tests. Neither state can be reached through the 8.x API: 8.x deletes an indexed attribute out of its indexes, and deleteCollection() removes the relationships pointing at the deleted collection. Reproducing either one takes direct surgery on stored metadata, which is how the library tests seed them (tests/e2e/Indexes/LegacyDroppedAttributeIndexTest.php and tests/e2e/Adapter/Scopes/Relationships/OrphanedTests.php in utopia-php/database). The full Databases, TablesDB and GraphQL suites run on 8.3.4 in CI.

Removed

  • The null case of the "row is not a stored record" check in Row::filter() and Document::filter(), which was [null, ''] and is now ''. It existed only because 8.3.0 returned distinct rows with $id = null. The '' case stays for unmatched outer-join rows.
  • testFilterRemovesTheEmptyStoredAttributesOfADistinctRecord in RowTest and DocumentTest, which pinned that null-$id shape. testFilterAddsNoStoredAttributesToADistinctRecord and testFilterKeepsTheIdADistinctRecordSelects replace it.

I found no other server code that 8.3.2 makes redundant. The aggregate-overflow mapping was already left to the library (ec8f3b0). The spatial and paging checks in packages/query belong to that library's own builder.

Test plan

I ran each test locally against the full Appwrite stack in three states, one stack per engine (_APP_DB_ADAPTER = postgresql, mariadb, mongodb, matching the CI lanes):

  • 8.3.0: main plus the tests only (commit 1).
  • 8.3.4: the 8.3.4 lock with commit 2's src/, which is the bump without the server change. 8.3.2 gave the same results on PostgreSQL and MariaDB.
  • 8.3.4 + fix: this PR's head.

Each cell covers TablesDBCustomServerTest, TablesDBCustomClientTest, LegacyCustomServerTest and LegacyCustomClientTest. The four always gave the same result. The transaction and GraphQL rows use the TablesDB and Legacy variants of their suites. "skip" means the adapter lacks the capability (MongoDB has no aggregations, distinct or spatial types), and these tests skip on DocumentsDB, which has no attributes. Where an adapter lacks aggregations, tests 1–3 assert a clean 400 general_query_invalid instead of skipping.

# Test (QA report) PostgreSQL 8.3.0 MariaDB 8.3.0 MongoDB 8.3.0 PostgreSQL 8.3.4 MariaDB 8.3.4 MongoDB 8.3.4 all lanes 8.3.4 + fix
1 testBitwiseAggregatesAreSigned64BitIntegers: bitAnd/bitOr/bitXor of 10 and −5 are 10, −5, −15 pass fail: unsigned 1.8e19 floats pass (refused, 400) pass pass pass (refused, 400) pass
2 testIntegerSumPastInt64IsRejected: sum of two INT64_MAX is 400 database_query_out_of_range; INT64_MAX−1 + 1 is exactly 9223372036854775807 fail: 200 with 1.8446744073709552e+19 fail: 200 with 1.8446744073709552e+19 pass (refused, 400) pass pass pass (refused, 400) pass
3 testPermissionsMinAndMaxAreRejected: max/min of $permissions is 400 general_query_invalid fail: 400, but from the engine ("Query applies a function or operator the attribute type does not support") fail: 200 with [] pass (refused, 400) pass pass pass (refused, 400) pass
4 testOutOfRangeSpatialFilterIsRejected: intersects("pt",[[200,100]]), latitude −91 and 100, longitude 181 are 400 fail: 200 with no rows fail: 200 with no rows skip pass pass skip pass
5 testMalformedWktIsRejectedOnWrite: {"pt":"POINT(1 2"} on create and update is 400 row_invalid_structure / document_invalid_structure fail: 500 fail: 201, stored as [0,0] skip pass pass skip pass
6 testInvalidRegexIsRejected: regex("s","((") is 400 "Invalid regular expression" fail: 500 fail: 500 fail: 500 pass pass pass pass
7 testFilterValuesThatAreNotAListAreRejected: values sent as {"a":1} is 400 "… query values must be a list" fail: 400 after an Undefined array key 0 warning fail: same fail: same pass pass pass pass
8 testCursorAlongAnUncomparableOrderIsRejected: orderAsc on an array (and spatial) column with cursorAfter is 400; without the cursor it is 200 fail: 500 (TypeError in Query::greaterThan) fail: 500 fail: 200, paged silently pass pass pass pass
9a testCachedDistinctRowsCarryOnlyTheSelectedAttributes: distinct + select(["grp"]) with ttl=60, twice, is 200 both times, the second X-Appwrite-Cache: hit, with only the selected keys (also with $id selected) fail: the hit is 400 "$id must be of type string" fail: same skip fail: invented $sequence, $createdAt, $updatedAt, $databaseId, $tableId fail: same as PostgreSQL skip pass
9b testDistinctRowsCarryOnlyTheSelectedAttributes (existing, uncached) pass pass skip fail: same invented keys fail: same as PostgreSQL skip pass
9c testDistinctReadInATransactionCarriesOnlyTheSelectedAttributes (Transactions, TablesDB + Legacy): committed rows, then again with a staged create¹ pass pass skip fail: invented keys fail: same as PostgreSQL skip pass
9d testDistinctRowsCarryNoStoredFields (GraphQL, TablesDB + Legacy): _id, _sequence, _createdAt, _updatedAt, _permissions are null, and data holds only name pass pass skip fail: _sequence is "" fail: same as PostgreSQL skip pass

¹ The staged-create step was added with commit 5, so the 8.3.0 and 8.3.4 cells for 9c cover only the committed read. With 8.3.4 plus commit 3 but not commit 5, the staged step fails on MariaDB: the staged row comes back as {"$id":"…","$createdAt":null,"$updatedAt":null,"$permissions":[],"name":"distinct-c"}. TransactionStateTest::testStagedCreateInADistinctReadCarriesOnlyTheSelectedAttributes fails the same way without commit 5.

Also run locally:

  • tests/unit/Utopia/Response and tests/unit/Databases/TransactionStateTest.php
  • The TablesDB/Transactions (190 tests) and Databases/Transactions (380) suites on MariaDB, at head
  • The full TablesDB (1030 tests), Databases (2467) and GraphQL (537) E2E suites on PostgreSQL and MariaDB on 8.3.2 + fix. All passed except two VectorsDB embedding tests that need the embedding compose profile, which CI enables for that lane.
  • Pint, PHPStan and Rector (tests/tools/rector.php) on the changed files
  • bin/monorepo validate

🤖 Generated with Claude Code

abnegate and others added 3 commits October 16, 2026 17:53
…ixes

Each test reproduces a QA report at the API, on rows and documents, and
fails on 8.3.0: bitwise aggregates answered unsigned on MariaDB, a sum past
INT64_MAX came back as an inexact float, min/max of $permissions answered
[] on MariaDB, out-of-range spatial filters were accepted, malformed WKT
was a 500 or silently stored as POINT(0 0) on MariaDB, an invalid regex
was a 500, filter values given as an object warned, a cursor along an
array order was a 500 or paged silently on MongoDB, and a cached distinct
read failed on the hit with "$id must be of type string".

The distinct tests also cover GraphQL and transactions, where a distinct
row must carry no stored fields.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
8.3.2 fixes the query bugs the previous commit reproduces at the API. The
absorbed packages require it too, so none of them can resolve a release
with those bugs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Since utopia-php/database 8.3.2 a distinct row carries no $id unless it
is selected, where 8.3.0 gave it a null one. The response models keyed
"not a stored record" on that null $id, so a distinct row now fell
through to the stored-record branch: it gained empty $sequence,
$createdAt and $updatedAt, and kept the $databaseId and table or
collection id the metadata decorator stamps on every row find returns.
That reached REST, GraphQL and reads inside a transaction alike.

A distinct row is hydrated as an Aggregate on every path that lists
rows: the read, the cache hit and the transaction read. Aggregate rows
gain no stored attributes and drop the location metadata, so a distinct
row carries what it selects, $id included when selected. The null $id
case is gone with the library behaviour it served.

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

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

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

  • 🟡 Distinct reads inside a transaction leak stored attributes — XList.php:169

The change reworks how distinct and aggregate query rows are serialized: distinct rows keep $id only when selected, while aggregate rows have location attributes stripped in the new Aggregate document class, with matching filter branches added to the Document and Row response models. The list-documents endpoint routes distinct reads in transactions through the new Aggregate wrapper, and new e2e suites lock the aggregate shape, rejected values, statistical aggregates, transaction distinct reads, and GraphQL join behavior. One real gap remains: the transaction distinct path can leak stored attributes ($id, $createdAt, $updatedAt, $permissions) that the non-transaction distinct path does not return, because applyProjection force-preserves internals before the Aggregate wrapper is applied.

Files Change
src/Appwrite/Utopia/Response/Model/Document.php, src/Appwrite/Utopia/Response/Model/Row.php Response-model filter branches for empty $id and Aggregate rows; distinct rows keep selected stored fields
src/Appwrite/Utopia/Database/Documents/Aggregate.php New Aggregate document class marking aggregate/distinct rows and stripping location attributes
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php List-documents routing for distinct/aggregation reads, including the transaction path wrapping rows in Aggregate
tests/unit/Utopia/Response/Model/DocumentTest.php, tests/unit/Utopia/Response/Model/RowTest.php Unit tests for the new filter branches
tests/e2e/Services/Databases/Queries/*.php New e2e suites: aggregate shape, rejected values, statistical aggregates (INT64 overflow, bitwise signedness, spatial/regex/cursor validation)
tests/e2e/Services/Databases/Transactions/TransactionsBase.php, tests/e2e/Services/GraphQL/QueryJoinCombos.php Distinct-read-in-transaction and GraphQL distinct join coverage
packages/*/composer.json Version bumps for absorbed packages (abuse, audit, migration, usage)

Reviewed commit: 564d534

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

@ghost

ghost commented Oct 16, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The incremental transaction projection change is consistent with distinct aggregate response handling, and no actionable defect was found.

The pull request upgrades utopia-php/database to 8.3.4 and adds API coverage for query validation, aggregate, spatial, cursor, and distinct-result behavior. It also hydrates distinct results as aggregates across normal, cached, and transactional reads, preserving only selected fields in response models, including for staged transaction creates.

Latest changes: The newest commit makes staged creates in distinct transaction reads keep only the selected attributes and adds unit and API regression coverage for that case.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 23
File Change
composer.lock, packages/abuse/composer.json, packages/audit/composer.json, packages/migration/composer.json, packages/usage/composer.json Locks the database dependency at 8.3.4 and updates absorbed package constraints.
src/Appwrite/Databases/TransactionState.php Projects staged transaction results without stored-record metadata for distinct selections.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php, src/Appwrite/Utopia/Database/Documents/Aggregate.php Hydrates distinct results as aggregates on normal, cached, and transactional paths.
src/Appwrite/Utopia/Response/Model/Document.php, src/Appwrite/Utopia/Response/Model/Row.php Keeps aggregate responses free of stored-record fields and location metadata.
tests/e2e/Services/Databases/Queries/AggregateShape.php, tests/e2e/Services/Databases/Queries/RejectedValues.php, tests/e2e/Services/Databases/Queries/StatisticalAggregates.php Covers distinct response shapes and invalid query, aggregate, spatial, regex, and cursor cases.
tests/e2e/Services/Databases/Transactions/TransactionsBase.php, tests/unit/Databases/TransactionStateTest.php Tests selected-field shapes for distinct reads with committed and staged transaction rows.
tests/e2e/Services/GraphQL/QueryJoinCombos.php Verifies GraphQL distinct results omit stored-record fields.
tests/unit/Utopia/Response/Model/DocumentTest.php, tests/unit/Utopia/Response/Model/RowTest.php Covers aggregate filtering and preservation of selected IDs.
composer.lock Locks utopia-php/database at 8.3.4.
packages/abuse/composer.json Raises the database dependency constraint to ^8.3.4.
packages/audit/composer.json Raises the database dependency constraint to ^8.3.4.
packages/migration/composer.json Raises the database dependency constraint to ^8.3.4.
packages/usage/composer.json Raises the database dependency constraint to ^8.3.4.
src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/XList.php Hydrates distinct results as aggregates on normal, cached, and transaction reads.
src/Appwrite/Utopia/Database/Documents/Aggregate.php Documents the aggregate model's use for distinct results and selected attributes.
src/Appwrite/Utopia/Response/Model/Document.php Avoids adding stored-record attributes or location metadata to aggregate responses.
src/Appwrite/Utopia/Response/Model/Row.php Avoids adding stored-record attributes or location metadata to aggregate responses.
tests/e2e/Services/Databases/Queries/AggregateShape.php Covers cached distinct response shapes and selected IDs.
tests/e2e/Services/Databases/Queries/RejectedValues.php Adds API tests for invalid query values, spatial inputs, regexes, and cursor ordering.
tests/e2e/Services/Databases/Queries/StatisticalAggregates.php Adds API tests for signed bitwise results, integer overflow, and unsupported permission aggregates.
tests/e2e/Services/Databases/Transactions/TransactionsBase.php Covers selected-attribute shapes for distinct reads inside transactions.
tests/unit/Utopia/Response/Model/DocumentTest.php Tests aggregate response filtering and preservation of selected IDs.
tests/unit/Utopia/Response/Model/RowTest.php Tests aggregate row filtering and preservation of selected IDs.

Merged main (0fe6fcd); no changes to this PR's code since c72d543 · 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

@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 fixes distinct and aggregate query response shaping for Documents/TablesDB and GraphQL, adds e2e coverage for aggregate edge cases, and bumps several package composer versions.

Key findings

  • 🟡 Distinct reads inside a transaction leak stored attributes — XList.php:169

@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → qfix-bump-database-832 (after).

Metric Before After Change
🚀 Requests/sec 217.01 220.5 ⚪ +1.6%
⏱️ Latency P50 78.57 ms 78.3 ms ⚪ -0.3%
⏱️ Latency P95 189.64 ms 182.95 ms ⚪ -3.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 78.3 182.95 13,680 220.5 -6.69
Account 149.81 292.61 720 12.38 +5.48
TablesDB 76.18 155.22 7,440 122.87 +4.28
Storage 70.69 158.62 3,600 60.99 -4.5
Functions 107.52 202.55 1,920 33.1 -18.49

Top API waits (after)

API request Max wait (ms)
account.prefs.update 479.37
account.name.update 451.54
tablesdb.rows.create 445.37
functions.create 372.19
account.get 332.02

8.3.3 reads a stored index whose attributes 7.x left null when an
indexed attribute was deleted, which made whole collections unreadable,
console teams among them. 8.3.4 treats a relationship whose related
collection 7.x deleteCollection() left behind as a plain attribute
instead of failing every read and write with "Collection not found".

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@abnegate abnegate changed the title chore(deps): bump utopia-php/database to 8.3.2 chore(deps): bump utopia-php/database to 8.3.4 Oct 16, 2026
abnegate and others added 2 commits October 16, 2026 20:13
A distinct read inside a transaction appends staged creates through
applyProjection(), which always kept $id, $collection, $createdAt,
$updatedAt and $permissions. Those rows reached the response with stored
fields the committed distinct rows lack, so one response mixed two
shapes. A distinct projection now keeps only the selected attributes, as
the library does for the rows it reads.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@abnegate
abnegate merged commit cb323ef into main Oct 16, 2026
227 checks passed
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