diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index d3194bcdcf..eaca5be920 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -4435,6 +4435,10 @@ App::put('/v1/databases/:databaseId/collections/:collectionId/documents/:documen throw new Exception(Exception::DOCUMENT_INVALID_STRUCTURE, $e->getMessage()); } + if (empty($upserted[0])) { + $upserted[0] = $dbForProject->getDocument('database_' . $database->getSequence() . '_collection_' . $collection->getSequence(), $documentId); + } + $document = $upserted[0]; // Add $collectionId and $databaseId for all documents $processDocument = function (Document $collection, Document $document) use (&$processDocument, $dbForProject, $database) { diff --git a/tests/e2e/Services/Databases/DatabasesBase.php b/tests/e2e/Services/Databases/DatabasesBase.php index 15a6722058..2cc980a309 100644 --- a/tests/e2e/Services/Databases/DatabasesBase.php +++ b/tests/e2e/Services/Databases/DatabasesBase.php @@ -1704,6 +1704,7 @@ trait DatabasesBase { $databaseId = $data['databaseId']; $documentId = ID::unique(); + $document = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents/' . $documentId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -1721,6 +1722,7 @@ trait DatabasesBase $this->assertEquals(200, $document['headers']['status-code']); $this->assertCount(3, $document['body']['$permissions']); + $document = $this->client->call(Client::METHOD_GET, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents/' . $documentId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], @@ -1728,6 +1730,38 @@ trait DatabasesBase $this->assertEquals('Thor: Ragnarok', $document['body']['title']); + /** + * Resend same document for no change + * Had to add all attributes because of partial comparison $old->getAttributes() == $document->getAttributes() + * If nothing is upserted there will be a regular call to getDocument + */ + + $document = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents/' . $documentId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'data' => [ + 'title' => 'Thor: Ragnarok', + 'releaseYear' => 2000, + 'integers' => [], + 'birthDay' => null, + 'duration' => null, + 'starringActors' => [], + 'actors' => [], + 'tagline' => '', + 'description' => '', + ], + 'permissions' => [ + Permission::read(Role::users()), + Permission::update(Role::users()), + Permission::delete(Role::users()), + ], + ]); + + $this->assertEquals(200, $document['headers']['status-code']); + $this->assertEquals('Thor: Ragnarok', $document['body']['title']); + $this->assertCount(3, $document['body']['$permissions']); + $document = $this->client->call(Client::METHOD_PUT, '/databases/' . $databaseId . '/collections/' . $data['moviesId'] . '/documents/' . $documentId, array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'],