diff --git a/app/controllers/api/database.php b/app/controllers/api/database.php index 6693bc37f1..11adec3205 100644 --- a/app/controllers/api/database.php +++ b/app/controllers/api/database.php @@ -76,6 +76,10 @@ function createAttribute($collectionId, $attribute, $response, $dbForInternal, $ throw new Exception('Cannot set default value for required attribute', 400); } + if ($array && $default) { + throw new Exception('Cannot set default value for array attributes', 400); + } + try { $attribute = new Document([ '$id' => $collectionId.'_'.$attributeId, @@ -1591,7 +1595,7 @@ App::post('/v1/database/collections/:collectionId/documents') $usage ->setParam('database.documents.create', 1) ->setParam('collectionId', $collectionId) - ; + ; $audits ->setParam('event', 'database.documents.create') diff --git a/tests/e2e/Services/Database/DatabaseBase.php b/tests/e2e/Services/Database/DatabaseBase.php index 82e065224b..3f11154c49 100644 --- a/tests/e2e/Services/Database/DatabaseBase.php +++ b/tests/e2e/Services/Database/DatabaseBase.php @@ -1338,6 +1338,16 @@ trait DatabaseBase 'max' => 3, ]); + $defaultArray = $this->client->call(Client::METHOD_POST, '/database/collections/' . $collectionId . '/attributes/integer', array_merge([ + 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'] + ]), [ + 'attributeId' => 'defaultArray', + 'required' => false, + 'default' => 42, + 'array' => true, + ]); + $this->assertEquals(201, $email['headers']['status-code']); $this->assertEquals(201, $ip['headers']['status-code']); $this->assertEquals(201, $url['headers']['status-code']); @@ -1347,7 +1357,9 @@ trait DatabaseBase $this->assertEquals(201, $upperBound['headers']['status-code']); $this->assertEquals(201, $lowerBound['headers']['status-code']); $this->assertEquals(400, $invalidRange['headers']['status-code']); + $this->assertEquals(400, $defaultArray['headers']['status-code']); $this->assertEquals('Minimum value must be lesser than maximum value', $invalidRange['body']['message']); + $this->assertEquals('Cannot set default value for array attributes', $defaultArray['body']['message']); // wait for worker to add attributes sleep(3);