From e06c358db494943af8324015059afd194661be23 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 26 Sep 2025 00:50:25 +1200 Subject: [PATCH] Don't require data for delete operation --- .../Utopia/Database/Validator/Operation.php | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Utopia/Database/Validator/Operation.php b/src/Appwrite/Utopia/Database/Validator/Operation.php index 4632678940..6bc068a60f 100644 --- a/src/Appwrite/Utopia/Database/Validator/Operation.php +++ b/src/Appwrite/Utopia/Database/Validator/Operation.php @@ -24,6 +24,20 @@ class Operation extends Validator 'decrement' => true, ]; + /** @var array */ + private array $requiresData = [ + 'create' => true, + 'update' => true, + 'upsert' => true, + 'delete' => false, // Delete doesn't need data + 'increment' => true, + 'decrement' => true, + 'bulkCreate' => true, + 'bulkUpdate' => true, + 'bulkUpsert' => true, + 'bulkDelete' => true, + ]; + /** @var array */ private array $actions = [ 'create' => true, @@ -121,14 +135,23 @@ class Operation extends Validator return false; } - // Data must be present and must be array (can be empty) - if (!\array_key_exists('data', $value)) { - $this->description = "Missing required key: data"; - return false; - } - if (!\is_array($value['data'])) { - $this->description = "Key 'data' must be an array"; - 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 + if (!\array_key_exists('data', $value)) { + $this->description = "Missing required key: data"; + return false; + } + if (!\is_array($value['data'])) { + $this->description = "Key 'data' must be an array"; + return false; + } + } 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"; + return false; + } } return true;