From 93d8f1cfe7f3eb66fc6c05b3236421090231978e Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Oct 2025 23:03:52 +1300 Subject: [PATCH 1/6] Update src/Appwrite/Databases/TransactionState.php Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/Appwrite/Databases/TransactionState.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Databases/TransactionState.php b/src/Appwrite/Databases/TransactionState.php index 1caae8c629..495a7b70ef 100644 --- a/src/Appwrite/Databases/TransactionState.php +++ b/src/Appwrite/Databases/TransactionState.php @@ -49,15 +49,15 @@ class TransactionState switch ($action) { case 'create': - if ($documentId) { - $state[$collectionId][$documentId] = [ + $docId = $documentId ?? ($data['$id'] ?? null); + if ($docId) { + $state[$collectionId][$docId] = [ 'action' => 'create', 'document' => new Document($data), 'exists' => true ]; } break; - case 'update': if (isset($state[$collectionId][$documentId])) { // Update existing document in transaction state From 9813b98133bc0682c195a8c6bc5f64329cfb056d Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Oct 2025 23:05:43 +1300 Subject: [PATCH 2/6] Update src/Appwrite/Databases/TransactionState.php Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- src/Appwrite/Databases/TransactionState.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Databases/TransactionState.php b/src/Appwrite/Databases/TransactionState.php index 495a7b70ef..c20eac3d1a 100644 --- a/src/Appwrite/Databases/TransactionState.php +++ b/src/Appwrite/Databases/TransactionState.php @@ -79,7 +79,9 @@ class TransactionState break; case 'upsert': - $state[$collectionId][$documentId] = [ + $docId = $documentId ?? ($data['$id'] ?? null); + if (!$docId) { break; } + $state[$collectionId][$docId] = [ 'action' => 'upsert', 'document' => new Document($data), 'exists' => true From 51d5ddb4637d0de70e21eb2ccc96842f40ad0415 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Oct 2025 23:17:17 +1300 Subject: [PATCH 3/6] Update src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../Http/Databases/Collections/Documents/Bulk/Upsert.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php index 6123454a8b..e5ae97ba7c 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php @@ -124,7 +124,7 @@ class Upsert extends Action if (($existing + 1) > $maxBatch) { throw new Exception( Exception::TRANSACTION_LIMIT_EXCEEDED, - 'Transaction already has ' . $existing . ' operations, adding ' . \count($documents) . ' would exceed the maximum of ' . $maxBatch + 'Transaction already has ' . $existing . ' operations, adding 1 would exceed the maximum of ' . $maxBatch ); } From 6581d68e6d9daf40b7cbf44f065fdb64862ac477 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Oct 2025 23:20:02 +1300 Subject: [PATCH 4/6] Update src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../Http/Databases/Collections/Documents/Bulk/Upsert.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php index e5ae97ba7c..2c8d26020d 100644 --- a/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php +++ b/src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Bulk/Upsert.php @@ -144,7 +144,7 @@ class Upsert extends Action 'transactions', $transactionId, 'operations', - \count($staged) + 1 ); }); From a9a97b2fe0b735fa006d7f3d9bbd346be41f0709 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Oct 2025 23:20:22 +1300 Subject: [PATCH 5/6] Update src/Appwrite/Platform/Modules/Databases/Http/Databases/Collections/Documents/Create.php Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../Databases/Http/Databases/Collections/Documents/Create.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 67a54068b8..902a3585ba 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 @@ -381,7 +381,7 @@ class Create extends Action if (($existing + 1) > $maxBatch) { throw new Exception( Exception::TRANSACTION_LIMIT_EXCEEDED, - 'Transaction already has ' . $existing . ' operations, adding ' . \count($documents) . ' would exceed the maximum of ' . $maxBatch + 'Transaction already has ' . $existing . ' operations, adding 1 would exceed the maximum of ' . $maxBatch ); } From 45da32d5d9129c8b0815d2ec0b7a82d2af9e82e2 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Thu, 2 Oct 2025 23:57:30 +1300 Subject: [PATCH 6/6] Update src/Appwrite/Utopia/Database/Validator/Operation.php Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../Utopia/Database/Validator/Operation.php | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Utopia/Database/Validator/Operation.php b/src/Appwrite/Utopia/Database/Validator/Operation.php index a8de32de79..5cc3ca2135 100644 --- a/src/Appwrite/Utopia/Database/Validator/Operation.php +++ b/src/Appwrite/Utopia/Database/Validator/Operation.php @@ -127,14 +127,25 @@ class Operation extends Validator } // If action requires documentId, it must be present - if ( - isset($this->requiresDocumentId[$value['action']]) && - !\array_key_exists($this->documentIdName, $value) - ) { +- if ( +- isset($this->requiresDocumentId[$value['action']]) && +- !\array_key_exists($this->documentIdName, $value) +- ) { +- $this->description = "Key '$this->documentIdName' is required for action '{$value['action']}'"; +- return false; + $actionRequiresDocumentId = ($this->requiresDocumentId[$value['action']] ?? false) === true; + if ($actionRequiresDocumentId && !\array_key_exists($this->documentIdName, $value)) { $this->description = "Key '$this->documentIdName' is required for action '{$value['action']}'"; return false; } + if (\array_key_exists($this->documentIdName, $value)) { + if (!\is_string($value[$this->documentIdName]) || \trim($value[$this->documentIdName]) === '') { + $this->description = "Key '$this->documentIdName' must be a non-empty string"; + return false; + } + } + // Data validation - only required for certain actions if (isset($this->requiresData[$value['action']]) && $this->requiresData[$value['action']]) { // Data is required for this action @@ -146,7 +157,7 @@ class Operation extends Validator $this->description = "Key 'data' must be an array"; return false; } - } elseif (\array_key_exists('data', $value)) { + } else if (\array_key_exists('data', $value)) { // Data is optional but if provided, must be an array if (!\is_array($value['data'])) { $this->description = "Key 'data' must be an array";