{"record":{"id":"b48a654492819336","repo":"passbolt/passbolt_api","slug":"the-metadata-key-does-not-exist-or-has-been-deleted-b48a65","errorCode":null,"errorMessage":"The metadata key does not exist or has been deleted.","messagePattern":"The metadata key does not exist or has been deleted\\.","errorType":"http","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Service/MetadataKey/MetadataKeyUpdateService.php","lineNumber":62,"sourceCode":"     * @throws \\Cake\\Http\\Exception\\NotFoundException if the key does not exist or is already expired\n     * @throws \\Cake\\Http\\Exception\\BadRequestException if the key id format is Invalid or some items are still using the key\n     */\n    public function update(UserAccessControl $uac, string $id, MetadataKeyUpdateDto $dto): void\n    {\n        $uac->assertIsAdmin();\n\n        if (!Validation::uuid($id)) {\n            throw new BadRequestException(__('The metadata key ID should be a valid UUID.'));\n        }\n\n        $metadataKeysTable = $this->fetchTable('Passbolt/Metadata.MetadataKeys');\n\n        // Assert the key exist\n        try {\n            /** @var \\Passbolt\\Metadata\\Model\\Entity\\MetadataKey $metadataKey */\n            $metadataKey = $metadataKeysTable->get($id);\n        } catch (RecordNotFoundException $exception) { // @phpstan-ignore-line\n            throw new NotFoundException(__('The metadata key does not exist or has been deleted.'), 404, $exception);\n        }\n\n        // Assert fingerprint is the same\n        if ($metadataKey->fingerprint !== $dto->fingerprint) {\n            throw new NotFoundException(__('The metadata key fingerprint is invalid.'));\n        }\n\n        // Assert the key is not already deleted\n        if ($metadataKey->isDeleted()) {\n            throw new NotFoundException(__('The metadata key has already been deleted.'));\n        }\n\n        // Assert they key was not previously marked as expired\n        if ($metadataKey->isExpired()) {\n            throw new BadRequestException(__('The metadata key is already marked as expired.'));\n        }\n\n        // Patch the key deleted field with the current time","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Service/MetadataKey/MetadataKeyUpdateService.php#L44-L80","documentation":"Existence check in MetadataKeyUpdateService::update(): after validating the id format, the service looks up the metadata key by id and, when no non-deleted key row matches, fails the admin's key-update operation with a not-found-style error. Fires when the key id refers to a key that was never created, or that has been soft-deleted; clients must refresh their key list and use an existing key id.","triggerScenarios":"PUT /metadata/keys/<valid-uuid> where the id is unknown, from another environment, or already deleted.","commonSituations":"Stale cached key list; wrong environment (staging id used against prod); key deleted by another admin in the meantime; DB reset without refreshing client data.","solutions":["Re-fetch GET /metadata/keys and confirm the id exists","Point the client at the correct environment/instance","Handle 404 by refreshing local key cache instead of retrying"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"const key = (await listMetadataKeys()).find(k => k.id === id);\nif (!key) throw new Error(`metadata key ${id} not found`);","typeGuard":null,"tryCatchPattern":"try {\n  await updateMetadataKey(id, dto);\n} catch (e) {\n  if (e.status === 404) await refreshKeyCache();\n  throw e;\n}","preventionTips":["Re-sync the key list before updates","Don't reuse ids across environments"],"tags":["not-found","metadata-keys","rest-api"],"backgroundTag":"entity-not-found","analyzedSha":"31c1bbc10f32808a607fa9bd81891e898779c0bc","analyzedAt":"2026-09-17T00:04:38.960Z","contentChangedAt":"2026-09-17T00:04:38.960Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}