From 578d4d161932f5bcb4b334dafc488d48bb147d39 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Fri, 31 Mar 2023 18:06:50 +1300 Subject: [PATCH] Disallow index creation on relationship attributes --- app/config/errors.php | 5 +++++ app/controllers/api/databases.php | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/app/config/errors.php b/app/config/errors.php index 82bde9d516..10e1b308f2 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -455,6 +455,11 @@ return [ 'description' => 'The attribute value is invalid. Please check the type, range and value of the attribute.', 'code' => 400, ], + Exception::ATTRIBUTE_TYPE_INVALID => [ + 'name' => Exception::ATTRIBUTE_TYPE_INVALID, + 'description' => 'The attribute type is invalid.', + 'code' => 400, + ], /** Indexes */ Exception::INDEX_NOT_FOUND => [ diff --git a/app/controllers/api/databases.php b/app/controllers/api/databases.php index 09f922ee97..0ac022aee3 100644 --- a/app/controllers/api/databases.php +++ b/app/controllers/api/databases.php @@ -2391,6 +2391,10 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes') $attributeType = $oldAttributes[$attributeIndex]['type']; $attributeSize = $oldAttributes[$attributeIndex]['size']; + if ($attributeType === Database::VAR_RELATIONSHIP) { + throw new Exception(Exception::ATTRIBUTE_TYPE_INVALID, 'Cannot create an index for a relationship attribute: ' . $oldAttributes[$attributeIndex]['key']); + } + // ensure attribute is available if ($attributeStatus !== 'available') { throw new Exception(Exception::ATTRIBUTE_NOT_AVAILABLE, 'Attribute not available: ' . $oldAttributes[$attributeIndex]['key']);