From 7dca2677270550dd6336e146133a1e2346ec52a8 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 1 Apr 2026 14:40:31 +1300 Subject: [PATCH] (fix): strip database prefix from internal collection name before mapping lookup The decorator receives full internal keys like 'database_2_collection_15' but the mapping uses relative keys like 'collection_15'. Strip the database prefix before looking up the mapping. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Appwrite/Utopia/Database/Hooks/Metadata.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Appwrite/Utopia/Database/Hooks/Metadata.php b/src/Appwrite/Utopia/Database/Hooks/Metadata.php index 0a7af8ce55..d34712373e 100644 --- a/src/Appwrite/Utopia/Database/Hooks/Metadata.php +++ b/src/Appwrite/Utopia/Database/Hooks/Metadata.php @@ -80,11 +80,23 @@ class Metadata implements Decorator return $this->collectionIdMap[$internalName]; } + // Strip database prefix if present (e.g., 'database_2_collection_15' → 'collection_15') + $databasePrefix = 'database_' . $this->database->getSequence() . '_'; + $relativeName = \str_starts_with($internalName, $databasePrefix) + ? \substr($internalName, \strlen($databasePrefix)) + : $internalName; + + if (isset($this->collectionIdMap[$relativeName])) { + $this->collectionIdMap[$internalName] = $this->collectionIdMap[$relativeName]; + return $this->collectionIdMap[$relativeName]; + } + if (!$this->mapLoaded && $this->dbForProject !== null && $this->authorization !== null) { $this->mapLoaded = true; $this->loadCollectionMap(); - if (isset($this->collectionIdMap[$internalName])) { - return $this->collectionIdMap[$internalName]; + if (isset($this->collectionIdMap[$relativeName])) { + $this->collectionIdMap[$internalName] = $this->collectionIdMap[$relativeName]; + return $this->collectionIdMap[$relativeName]; } }