From 2fad2f2f663f2e2ec57393db375003c1aeae146b Mon Sep 17 00:00:00 2001 From: Atharva Deosthale Date: Tue, 30 Jun 2026 12:08:11 +0530 Subject: [PATCH] Fix staged transaction write timestamps --- src/Appwrite/Utopia/Response/Model/Document.php | 2 ++ src/Appwrite/Utopia/Response/Model/Row.php | 2 ++ .../Databases/Transactions/TransactionsBase.php | 17 +++++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/Appwrite/Utopia/Response/Model/Document.php b/src/Appwrite/Utopia/Response/Model/Document.php index 3be003418d..aa4845a89d 100644 --- a/src/Appwrite/Utopia/Response/Model/Document.php +++ b/src/Appwrite/Utopia/Response/Model/Document.php @@ -85,6 +85,8 @@ class Document extends Any if (!$document->isEmpty()) { $document->setAttribute('$sequence', (string)$document->getAttribute('$sequence', '')); + $document->setAttribute('$createdAt', (string)$document->getAttribute('$createdAt', '')); + $document->setAttribute('$updatedAt', (string)$document->getAttribute('$updatedAt', '')); } foreach ($document->getAttributes() as $attribute) { diff --git a/src/Appwrite/Utopia/Response/Model/Row.php b/src/Appwrite/Utopia/Response/Model/Row.php index 4c7426c4bc..45ddf65af3 100644 --- a/src/Appwrite/Utopia/Response/Model/Row.php +++ b/src/Appwrite/Utopia/Response/Model/Row.php @@ -85,6 +85,8 @@ class Row extends Any if (!$document->isEmpty()) { $document->setAttribute('$sequence', (string)$document->getAttribute('$sequence', '')); + $document->setAttribute('$createdAt', (string)$document->getAttribute('$createdAt', '')); + $document->setAttribute('$updatedAt', (string)$document->getAttribute('$updatedAt', '')); } foreach ($document->getAttributes() as $column) { diff --git a/tests/e2e/Services/Databases/Transactions/TransactionsBase.php b/tests/e2e/Services/Databases/Transactions/TransactionsBase.php index c69c35f663..cbf0303438 100644 --- a/tests/e2e/Services/Databases/Transactions/TransactionsBase.php +++ b/tests/e2e/Services/Databases/Transactions/TransactionsBase.php @@ -100,6 +100,22 @@ trait TransactionsBase parent::tearDownAfterClass(); } + protected function assertStagedWriteResponseSystemAttributes(array $body, bool $empty = false): void + { + $this->assertArrayHasKey('$sequence', $body, 'Staged write response should include $sequence for SDK model hydration.'); + $this->assertArrayHasKey('$createdAt', $body, 'Staged write response should include $createdAt for SDK model hydration.'); + $this->assertArrayHasKey('$updatedAt', $body, 'Staged write response should include $updatedAt for SDK model hydration.'); + $this->assertIsString($body['$sequence']); + $this->assertIsString($body['$createdAt']); + $this->assertIsString($body['$updatedAt']); + + if ($empty) { + $this->assertSame('', $body['$sequence']); + $this->assertSame('', $body['$createdAt']); + $this->assertSame('', $body['$updatedAt']); + } + } + /** * Test creating a transaction */ @@ -1661,6 +1677,7 @@ trait TransactionsBase ]); $this->assertEquals(201, $response['headers']['status-code']); + $this->assertStagedWriteResponseSystemAttributes($response['body'], empty: true); // Document should not exist outside transaction yet $response = $this->client->call(Client::METHOD_GET, $this->getRecordUrl($databaseId, $collectionId, "doc_from_route"), array_merge([