From 2111aab8ed6a909ae1bbf8b08e27509286b3a35f Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 27 Aug 2025 16:09:56 +1200 Subject: [PATCH 1/4] Fix relationship request filter --- app/controllers/general.php | 2 +- src/Appwrite/Utopia/Request/Filters/V20.php | 70 ++++++++++++++++----- 2 files changed, 54 insertions(+), 18 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index a4f89d14c7..87f855ca19 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -875,7 +875,7 @@ App::init() } if (version_compare($requestFormat, '1.8.0', '<')) { $dbForProject = $getProjectDB($project); - $request->addFilter(new RequestV20($dbForProject, $request->getParams())); + $request->addFilter(new RequestV20($dbForProject, $route->getPathValues($request))); } } diff --git a/src/Appwrite/Utopia/Request/Filters/V20.php b/src/Appwrite/Utopia/Request/Filters/V20.php index 30de1fb2d3..e4d803b2a8 100644 --- a/src/Appwrite/Utopia/Request/Filters/V20.php +++ b/src/Appwrite/Utopia/Request/Filters/V20.php @@ -96,36 +96,72 @@ class V20 extends Filter /** * Returns all relationship attribute keys in `key.*` format for use with `Query::select`. */ - private function getRelatedCollectionKeys(): array + private function getRelatedCollectionKeys( + ?string $databaseId = null, + ?string $collectionId = null, + ?string $prefix = null, + int $depth = 1, + ): array { - $dbForProject = $this->getDbForProject(); + $databaseId ??= $this->getParamValue('databaseId'); + $collectionId ??= $this->getParamValue('collectionId'); + if ( + empty($databaseId) || + empty($collectionId) || + $depth > Database::RELATION_MAX_DEPTH + ) { + return []; + } + + $dbForProject = $this->getDbForProject(); if ($dbForProject === null) { return []; } - $databaseId = $this->getParamValue('databaseId'); - $collectionId = $this->getParamValue('collectionId'); - - if (empty($databaseId) || empty($collectionId)) { + $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); + if ($database->isEmpty()) { return []; } - $database = Authorization::skip(fn () => $dbForProject->getDocument('databases', $databaseId)); - - $collection = $dbForProject->getDocument( + $collection = Authorization::skip(fn () => $dbForProject->getDocument( 'database_' . $database->getSequence(), $collectionId - ); + )); + if ($collection->isEmpty()) { + return []; + } $attributes = $collection->getAttribute('attributes', []); + $relationshipKeys = []; - return \array_values(\array_map( - fn ($attr) => $attr['key'] . '.*', - \array_filter( - $attributes, - fn ($attr) => ($attr['type'] ?? null) === Database::VAR_RELATIONSHIP - ) - )); + foreach ($attributes as $attr) { + if (($attr['type'] ?? null) !== Database::VAR_RELATIONSHIP) { + continue; + } + + $key = $attr['key']; + $fullKey = $prefix ? $prefix . '.' . $key : $key; + + // Add the wildcard select for this relationship + $relationshipKeys[] = $fullKey . '.*'; + + // Get the related collection for nested relationships + $relatedCollectionId = $attr['relatedCollection'] ?? null; + + if ($relatedCollectionId) { + // Recursively get nested relationship keys + $nestedKeys = $this->getRelatedCollectionKeys( + $databaseId, + $relatedCollectionId, + $fullKey, + $depth + 1, + ); + + $relationshipKeys = \array_merge($relationshipKeys, $nestedKeys); + } + } + + return \array_values(\array_unique($relationshipKeys)); } } From 0e9cdc68b11ce322e551da932ed110f904594b07 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 27 Aug 2025 16:10:10 +1200 Subject: [PATCH 2/4] Bump console --- app/views/install/compose.phtml | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index 8e165e45e5..ed4de38d2b 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -179,7 +179,7 @@ $image = $this->getParam('image', ''); appwrite-console: <<: *x-logging container_name: appwrite-console - image: /console:6.2.0 + image: /console:7.0.2 restart: unless-stopped networks: - appwrite diff --git a/docker-compose.yml b/docker-compose.yml index 3471690a5b..87385aa086 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -219,7 +219,7 @@ services: appwrite-console: <<: *x-logging container_name: appwrite-console - image: appwrite/console:7.0.0-qa.8 + image: appwrite/console:7.0.2 restart: unless-stopped networks: - appwrite From f4c56ad7572e66b748346f5bac27c127ba8b4aba Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 27 Aug 2025 16:21:29 +1200 Subject: [PATCH 3/4] Format --- src/Appwrite/Utopia/Request/Filters/V20.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Appwrite/Utopia/Request/Filters/V20.php b/src/Appwrite/Utopia/Request/Filters/V20.php index e4d803b2a8..6ca6171eb9 100644 --- a/src/Appwrite/Utopia/Request/Filters/V20.php +++ b/src/Appwrite/Utopia/Request/Filters/V20.php @@ -101,8 +101,7 @@ class V20 extends Filter ?string $collectionId = null, ?string $prefix = null, int $depth = 1, - ): array - { + ): array { $databaseId ??= $this->getParamValue('databaseId'); $collectionId ??= $this->getParamValue('collectionId'); @@ -142,13 +141,13 @@ class V20 extends Filter $key = $attr['key']; $fullKey = $prefix ? $prefix . '.' . $key : $key; - + // Add the wildcard select for this relationship $relationshipKeys[] = $fullKey . '.*'; // Get the related collection for nested relationships $relatedCollectionId = $attr['relatedCollection'] ?? null; - + if ($relatedCollectionId) { // Recursively get nested relationship keys $nestedKeys = $this->getRelatedCollectionKeys( @@ -157,7 +156,7 @@ class V20 extends Filter $fullKey, $depth + 1, ); - + $relationshipKeys = \array_merge($relationshipKeys, $nestedKeys); } } From 4daad1b775d87537488aae8836502eb74b7adbb4 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 27 Aug 2025 16:48:08 +1200 Subject: [PATCH 4/4] Ignore relationships that are not available --- src/Appwrite/Utopia/Request/Filters/V20.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Appwrite/Utopia/Request/Filters/V20.php b/src/Appwrite/Utopia/Request/Filters/V20.php index 6ca6171eb9..2683d600ef 100644 --- a/src/Appwrite/Utopia/Request/Filters/V20.php +++ b/src/Appwrite/Utopia/Request/Filters/V20.php @@ -135,7 +135,10 @@ class V20 extends Filter $relationshipKeys = []; foreach ($attributes as $attr) { - if (($attr['type'] ?? null) !== Database::VAR_RELATIONSHIP) { + if ( + ($attr['type'] ?? null) !== Database::VAR_RELATIONSHIP || + $attr['status'] !== 'available' + ) { continue; }