Compare commits

...
Author SHA1 Message Date
57a811eb5d chore: update utopia-php/database to stable 5.* and run composer update
Agent-Logs-Url: https://github.com/appwrite/appwrite/sessions/045dbae8-cb3c-42ae-bfa0-144d0680ba26

Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com>
2026-04-29 07:29:48 +00:00
e985d8724b Merge remote-tracking branch 'origin/1.9.x' into unique-exception
# Conflicts:
#	composer.json
#	composer.lock
#	tests/e2e/Services/Databases/DatabasesBase.php

Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com>
2026-04-29 06:49:59 +00:00
fogelito a46fc5e153 Remove var_dump 2025-10-16 17:28:25 +03:00
fogelito 08ec06dfe5 linter 2025-10-16 17:13:42 +03:00
fogelito 46e6e34c8a Remove var_dumps 2025-10-16 17:09:46 +03:00
fogelito 0d95ba99d3 Add DOCUMENT_UNIQUE_VIOLATION 2025-10-16 16:59:02 +03:00
fogelito effd180e0b linter 2025-10-16 13:58:54 +03:00
fogelito 57f4ae7395 Merge branch '1.8.x' of https://github.com/appwrite/appwrite into unique-exception 2025-10-16 13:56:58 +03:00
fogelito 4d91f1a1b8 Merge branch '1.8.x' of https://github.com/appwrite/appwrite into unique-exception
# Conflicts:
#	composer.lock
2025-10-16 12:43:39 +03:00
fogelito d3dc178c27 Run tests 2025-10-16 12:38:49 +03:00
6 changed files with 66 additions and 6 deletions
+10
View File
@@ -797,6 +797,11 @@ return [
'description' => 'Document with the requested ID \'%s\' already exists. Try again with a different ID or use ID.unique() to generate a unique ID.',
'code' => 409,
],
Exception::DOCUMENT_UNIQUE_VIOLATION => [
'name' => Exception::DOCUMENT_UNIQUE_VIOLATION,
'description' => 'Document unique constraint violation. Please try again with different data.',
'code' => 409,
],
Exception::DOCUMENT_UPDATE_CONFLICT => [
'name' => Exception::DOCUMENT_UPDATE_CONFLICT,
'description' => 'Remote document is newer than local.',
@@ -834,6 +839,11 @@ return [
'description' => 'Row with the requested ID \'%s\' already exists. Try again with a different ID or use ID.unique() to generate a unique ID.',
'code' => 409,
],
Exception::ROW_UNIQUE_VIOLATION => [
'name' => Exception::ROW_UNIQUE_VIOLATION,
'description' => 'Row unique constraint violation. Please try again with different data.',
'code' => 409,
],
Exception::ROW_UPDATE_CONFLICT => [
'name' => Exception::ROW_UPDATE_CONFLICT,
'description' => 'Remote row is newer than local.',
Generated
+6 -6
View File
@@ -3850,16 +3850,16 @@
},
{
"name": "utopia-php/database",
"version": "5.3.22",
"version": "5.4.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/database.git",
"reference": "d765945da6b3141852014b2f96ecf1fe7e3d6ba7"
"reference": "7479a74d4e7c67a58689c0f45bf64b7c403ad54e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/database/zipball/d765945da6b3141852014b2f96ecf1fe7e3d6ba7",
"reference": "d765945da6b3141852014b2f96ecf1fe7e3d6ba7",
"url": "https://api.github.com/repos/utopia-php/database/zipball/7479a74d4e7c67a58689c0f45bf64b7c403ad54e",
"reference": "7479a74d4e7c67a58689c0f45bf64b7c403ad54e",
"shasum": ""
},
"require": {
@@ -3903,9 +3903,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/5.3.22"
"source": "https://github.com/utopia-php/database/tree/5.4.0"
},
"time": "2026-04-20T07:12:46+00:00"
"time": "2026-04-29T06:30:39+00:00"
},
{
"name": "utopia-php/detector",
+2
View File
@@ -222,6 +222,7 @@ class Exception extends \Exception
public const string DOCUMENT_MISSING_DATA = 'document_missing_data';
public const string DOCUMENT_MISSING_PAYLOAD = 'document_missing_payload';
public const string DOCUMENT_ALREADY_EXISTS = 'document_already_exists';
public const string DOCUMENT_UNIQUE_VIOLATION = 'document_unique_violation';
public const string DOCUMENT_UPDATE_CONFLICT = 'document_update_conflict';
public const string DOCUMENT_DELETE_RESTRICTED = 'document_delete_restricted';
@@ -231,6 +232,7 @@ class Exception extends \Exception
public const string ROW_MISSING_DATA = 'row_missing_data';
public const string ROW_MISSING_PAYLOAD = 'row_missing_payload';
public const string ROW_ALREADY_EXISTS = 'row_already_exists';
public const string ROW_UNIQUE_VIOLATION = 'row_unique_violation';
public const string ROW_UPDATE_CONFLICT = 'row_update_conflict';
public const string ROW_DELETE_RESTRICTED = 'row_delete_restricted';
@@ -168,6 +168,16 @@ abstract class Action extends DatabasesAction
: Exception::ROW_NOT_FOUND;
}
/**
* Get the appropriate unique violation exception.
*/
protected function getUniqueException(): string
{
return $this->isCollectionsAPI()
? Exception::DOCUMENT_UNIQUE_VIOLATION
: Exception::ROW_UNIQUE_VIOLATION;
}
/**
* Get the appropriate already exists exception.
*/
@@ -21,6 +21,7 @@ use Utopia\Database\Exception\Duplicate as DuplicateException;
use Utopia\Database\Exception\NotFound as NotFoundException;
use Utopia\Database\Exception\Relationship as RelationshipException;
use Utopia\Database\Exception\Structure as StructureException;
use Utopia\Database\Exception\Unique as UniqueException;
use Utopia\Database\Helpers\ID;
use Utopia\Database\Helpers\Permission;
use Utopia\Database\Helpers\Role;
@@ -469,6 +470,8 @@ class Create extends Action
);
}
);
} catch (UniqueException) {
throw new Exception($this->getUniqueException());
} catch (DuplicateException) {
throw new Exception($this->getDuplicateException(), params: [$documentId]);
} catch (NotFoundException) {
@@ -6092,6 +6092,41 @@ trait DatabasesBase
]);
$this->assertEquals(409, $duplicate['headers']['status-code']);
$this->assertEquals('Document with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', $duplicate['body']['message']);
}
public function testUniqueUid(): void
{
$data = $this->setupDocuments();
/**
* Test duplicate on unique $id
*/
$document = $this->client->call(Client::METHOD_POST, $this->getRecordUrl($data['databaseId'], $data['moviesId']), array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
$this->getRecordIdParam() => 'i_am_unique',
'data' => [
'title' => 'Hello 1',
'releaseYear' => 2000
]
]);
$this->assertEquals(201, $document['headers']['status-code']);
$document = $this->client->call(Client::METHOD_POST, $this->getRecordUrl($data['databaseId'], $data['moviesId']), array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
$this->getRecordIdParam() => 'i_am_unique',
'data' => [
'title' => 'Hello 2',
'releaseYear' => 2000
]
]);
$this->assertEquals(409, $document['headers']['status-code']);
$this->assertEquals('Document with the requested ID already exists. Try again with a different ID or use ID.unique() to generate a unique ID.', $document['body']['message']);
}
public function testPersistentCreatedAt(): void