Merge pull request #13407 from appwrite/cursor/fix-transaction-bulk-query-parse-44d3

Fix TypeError committing transaction bulkDelete with array queries
This commit is contained in:
Chirag Aggarwal authored and GitHub committed 2026-09-02 05:00:32 -07:00
commit 4c4b59e60b
2 files changed
+128

No files matched your search

@@ -177,6 +177,12 @@ class Operation extends Validator
$this->description = "Key 'queries' must be an array for {$action}";
return false;
}
foreach ($value['data']['queries'] as $query) {
if (!\is_string($query)) {
$this->description = "Key 'data.queries' must contain only strings for {$action}";
return false;
}
}
}
// BulkUpdate requires both queries and data
@@ -2668,6 +2668,128 @@ trait TransactionsBase
$this->assertEquals(0, $response['body']['total']);
}
/**
* Reject bulkUpdate/bulkDelete with decoded query arrays.
*/
public function testCreateBulkOperationsWithArrayQueries(): void
{
// Test for FAILURE
$database = $this->client->call(Client::METHOD_POST, $this->getDatabaseUrl(), array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'databaseId' => ID::unique(),
'name' => 'BulkArrayQueriesTestDB'
]);
$databaseId = $database['body']['$id'];
$collection = $this->client->call(Client::METHOD_POST, $this->getContainerUrl($databaseId), array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
$this->getContainerIdParam() => ID::unique(),
'name' => 'TestCollection',
'permissions' => [
Permission::create(Role::any()),
Permission::read(Role::any()),
Permission::update(Role::any()),
Permission::delete(Role::any()),
],
]);
$collectionId = $collection['body']['$id'];
if ($this->getSupportForAttributes()) {
$this->client->call(Client::METHOD_POST, $this->getSchemaUrl($databaseId, $collectionId, "string", null), array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'key' => 'name',
'size' => 256,
'required' => true,
]);
$this->client->call(Client::METHOD_POST, $this->getSchemaUrl($databaseId, $collectionId, "string", null), array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'key' => 'category',
'size' => 256,
'required' => false,
]);
$this->waitForAllAttributes($databaseId, $collectionId);
}
foreach (['keep_1', 'keep_2', 'drop_1', 'drop_2'] as $id) {
$category = \str_starts_with($id, 'keep') ? 'keep' : 'drop';
$this->client->call(Client::METHOD_POST, $this->getRecordUrl($databaseId, $collectionId, null), array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
$this->getRecordIdParam() => $id,
'data' => [
'name' => $id,
'category' => $category,
]
]);
}
$transaction = $this->client->call(Client::METHOD_POST, $this->getTransactionUrl(), array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(201, $transaction['headers']['status-code']);
$transactionId = $transaction['body']['$id'];
$response = $this->client->call(Client::METHOD_POST, $this->getTransactionUrl($transactionId) . "/operations", array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'operations' => [
[
'databaseId' => $databaseId,
$this->getContainerIdParam() => $collectionId,
'action' => 'bulkUpdate',
'data' => [
'queries' => [Query::equal('category', ['keep'])->toArray()],
'data' => ['name' => 'updated'],
],
],
]
]);
$this->assertEquals(400, $response['headers']['status-code']);
$this->assertEquals('general_argument_invalid', $response['body']['type']);
$response = $this->client->call(Client::METHOD_POST, $this->getTransactionUrl($transactionId) . "/operations", array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey']
]), [
'operations' => [
[
'databaseId' => $databaseId,
$this->getContainerIdParam() => $collectionId,
'action' => 'bulkDelete',
'data' => [
'queries' => [Query::equal('category', ['drop'])->toArray()],
],
],
]
]);
$this->assertEquals(400, $response['headers']['status-code']);
$this->assertEquals('general_argument_invalid', $response['body']['type']);
}
/**
* Test multiple single route operations in one transaction
*/