diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php index ca5dc91cb4..78df15b0c1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Action.php @@ -29,7 +29,7 @@ abstract class Action extends AppwriteAction // Use the same helper method to ensure consistency $contextId = '$' . $this->getCollectionsEventsContext() . 'Id'; - $this->removableAttributes = ['$databaseId', $contextId]; + $this->removableAttributes = ['$databaseId', $contextId, '$sequence']; return parent::setHttpPath($path); } diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php index b5a4750c4f..a9f9c3f76d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Update.php @@ -127,6 +127,9 @@ class Update extends Action } } + // Remove sequence if set + unset($document['$sequence']); + $documents = []; try { diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php index f2d678f411..04c90c4ec1 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php @@ -351,6 +351,9 @@ class Create extends Action } } + // Remove sequence if set + unset($document['$sequence']); + // Assign a unique ID if needed, otherwise use the provided ID. $document['$id'] = $sourceId === 'unique()' ? ID::unique() : $sourceId; diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php index 4f5055abc4..334bcb8448 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Update.php @@ -159,6 +159,9 @@ class Update extends Action $permissions = $document->getPermissions() ?? []; } + // Remove sequence if set + unset($document['$sequence']); + $data['$id'] = $documentId; $data['$permissions'] = $permissions; $newDocument = new Document($data); diff --git a/src/Appwrite/Utopia/Request/Filters/V20.php b/src/Appwrite/Utopia/Request/Filters/V20.php index 939eeeabe7..30de1fb2d3 100644 --- a/src/Appwrite/Utopia/Request/Filters/V20.php +++ b/src/Appwrite/Utopia/Request/Filters/V20.php @@ -52,7 +52,7 @@ class V20 extends Filter if (empty($selections)) { $hasWildcard = true; $parsed[] = Query::select(['*']); - } else if (!$hasWildcard) { + } elseif (!$hasWildcard) { // check if any select includes a wildcard as we added one above foreach ($selections as $select) { if (\in_array('*', $select->getValues(), true)) { diff --git a/src/Appwrite/Utopia/Response/Model/Row.php b/src/Appwrite/Utopia/Response/Model/Row.php index 77df48ce89..370d3065ba 100644 --- a/src/Appwrite/Utopia/Response/Model/Row.php +++ b/src/Appwrite/Utopia/Response/Model/Row.php @@ -79,6 +79,7 @@ class Row extends Any { $document->removeAttribute('$collection'); $document->removeAttribute('$tenant'); + $document->setAttribute('$sequence', (int)$document->getAttribute('$sequence', 0)); foreach ($document->getAttributes() as $column) { if (\is_array($column)) { diff --git a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php index 0b92208c95..c57421c384 100644 --- a/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php +++ b/tests/e2e/Services/Databases/TablesDB/DatabasesBase.php @@ -1625,6 +1625,8 @@ trait DatabasesBase $this->assertEquals($row1['body']['actors'][0], 'Chris Evans'); $this->assertEquals($row1['body']['actors'][1], 'Samuel Jackson'); $this->assertEquals($row1['body']['birthDay'], '1975-06-12T12:12:55.000+00:00'); + $this->assertTrue(array_key_exists('$sequence', $row1['body'])); + $this->assertIsInt($row1['body']['$sequence']); $this->assertEquals(201, $row2['headers']['status-code']); $this->assertEquals($data['moviesId'], $row2['body']['$tableId']);