Repository navigation
chore(deps): bump utopia-php/database to 8.3.4 - #14576
Conversation
…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]>
|
Review complete. 🟡 1 medium 💬 Inline comments (1)
The change reworks how distinct and aggregate query rows are serialized: distinct rows keep
Reviewed commit: 564d534 |
Security rulesNo new WARNING or ERROR findings from security rules. 19 existing findings tracked in
|
🟢 Tier S · Ready to merge
The pull request upgrades 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.
📂 Walkthrough · 23
Merged |
There was a problem hiding this comment.
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
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
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]>
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]>
What does this PR do?
Bumps
utopia-php/databasefrom 8.3.0 to 8.3.4 (root constraint stays^8.3; the absorbedabuse,audit,migrationandusagepackages 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 leftnull(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
$idunless$idis selected. 8.3.0 gave it a null one, and the response models used that null$idto tell a non-stored row apart. Without it, a distinct row fell through to the stored-record branch: it picked up empty$sequence,$createdAtand$updatedAt, and kept the$databaseIdand$tableId/$collectionIdthat the metadata decorator stamps on every rowfind()returns. That happened in REST, GraphQL and reads inside a transaction.Commits
test(databases): the E2E tests on their own, run against main (8.3.0) to show they fail first.chore(deps): the bump to 8.3.2.fix(databases): distinct rows are hydrated asAggregateon every path that lists rows: the read (cache miss), the cache hit and the transaction read. TheRowandDocumentmodels add no stored attributes to anAggregaterow and drop its location metadata ($databaseId,$tableId/$collectionId). A distinct row now carries only what it selects, including$idwhen$idis selected.chore(deps): the bump to 8.3.4.fix(databases): a distinct read inside a transaction adds staged creates throughTransactionState::applyProjection(), which always kept$id,$collection,$createdAt,$updatedAtand$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.phpandtests/e2e/Adapter/Scopes/Relationships/OrphanedTests.phpin utopia-php/database). The full Databases, TablesDB and GraphQL suites run on 8.3.4 in CI.Removed
nullcase of the "row is not a stored record" check inRow::filter()andDocument::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.testFilterRemovesTheEmptyStoredAttributesOfADistinctRecordinRowTestandDocumentTest, which pinned that null-$idshape.testFilterAddsNoStoredAttributesToADistinctRecordandtestFilterKeepsTheIdADistinctRecordSelectsreplace 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/querybelong 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):src/, which is the bump without the server change. 8.3.2 gave the same results on PostgreSQL and MariaDB.Each cell covers
TablesDBCustomServerTest,TablesDBCustomClientTest,LegacyCustomServerTestandLegacyCustomClientTest. 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 400general_query_invalidinstead of skipping.testBitwiseAggregatesAreSigned64BitIntegers: bitAnd/bitOr/bitXor of 10 and −5 are 10, −5, −15testIntegerSumPastInt64IsRejected: sum of two INT64_MAX is 400database_query_out_of_range; INT64_MAX−1 + 1 is exactly 92233720368547758071.8446744073709552e+191.8446744073709552e+19testPermissionsMinAndMaxAreRejected: max/min of$permissionsis 400general_query_invalid[]testOutOfRangeSpatialFilterIsRejected:intersects("pt",[[200,100]]), latitude −91 and 100, longitude 181 are 400testMalformedWktIsRejectedOnWrite:{"pt":"POINT(1 2"}on create and update is 400row_invalid_structure/document_invalid_structure[0,0]testInvalidRegexIsRejected:regex("s","((")is 400 "Invalid regular expression"testFilterValuesThatAreNotAListAreRejected:valuessent as{"a":1}is 400 "… query values must be a list"Undefined array key 0warningtestCursorAlongAnUncomparableOrderIsRejected:orderAscon an array (and spatial) column withcursorAfteris 400; without the cursor it is 200Query::greaterThan)testCachedDistinctRowsCarryOnlyTheSelectedAttributes: distinct +select(["grp"])withttl=60, twice, is 200 both times, the secondX-Appwrite-Cache: hit, with only the selected keys (also with$idselected)$sequence,$createdAt,$updatedAt,$databaseId,$tableIdtestDistinctRowsCarryOnlyTheSelectedAttributes(existing, uncached)testDistinctReadInATransactionCarriesOnlyTheSelectedAttributes(Transactions, TablesDB + Legacy): committed rows, then again with a staged create¹testDistinctRowsCarryNoStoredFields(GraphQL, TablesDB + Legacy):_id,_sequence,_createdAt,_updatedAt,_permissionsare null, anddataholds onlyname_sequenceis""¹ 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::testStagedCreateInADistinctReadCarriesOnlyTheSelectedAttributesfails the same way without commit 5.Also run locally:
tests/unit/Utopia/Responseandtests/unit/Databases/TransactionStateTest.phpTablesDB/Transactions(190 tests) andDatabases/Transactions(380) suites on MariaDB, at headTablesDB(1030 tests),Databases(2467) andGraphQL(537) E2E suites on PostgreSQL and MariaDB on 8.3.2 + fix. All passed except two VectorsDB embedding tests that need theembeddingcompose profile, which CI enables for that lane.tests/tools/rector.php) on the changed filesbin/monorepo validate🤖 Generated with Claude Code