Merge pull request #13454 from appwrite/fix/atomic-bucket-create

fix(storage): remove the bucket document when its files collection cannot be created
This commit is contained in:
Luke B. Silver authored and GitHub committed 2026-09-02 17:11:20 +01:00
commit 60493877e0
1 file changed
+10 -1
@@ -153,7 +153,16 @@ class Create extends Action
$bucket = $dbForProject->getDocument('buckets', $bucketId);
$dbForProject->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes, permissions: $permissions, documentSecurity: $fileSecurity);
// The files collection is DDL and cannot share a transaction with the
// document insert above, and its name needs the document's sequence,
// so the document is committed first. A bucket without its collection
// can never hold a file: remove it rather than leave an orphan.
try {
$dbForProject->createCollection('bucket_' . $bucket->getSequence(), $attributes, $indexes, permissions: $permissions, documentSecurity: $fileSecurity);
} catch (\Throwable $th) {
$dbForProject->deleteDocument('buckets', $bucketId);
throw $th;
}
} catch (DuplicateException) {
throw new Exception(Exception::STORAGE_BUCKET_ALREADY_EXISTS);
}