{"record":{"id":"55fd2dfe9ae754b5","repo":"passbolt/passbolt_api","slug":"the-metadata-private-key-does-not-exist-or-has-been-deleted","errorCode":null,"errorMessage":"The metadata private key does not exist or has been deleted.","messagePattern":"The metadata private key does not exist or has been deleted\\.","errorType":"exception","errorClass":"NotFoundException","httpStatus":404,"severity":"error","filePath":"plugins/PassboltCe/Metadata/src/Service/MetadataPrivateKeysUpdateService.php","lineNumber":65,"sourceCode":"    public function update(UserAccessControl $uac, string $privateKeyId, array $data): MetadataPrivateKey\n    {\n        if (!isset($data['data']) || !is_string($data['data'])) {\n            throw new BadRequestException(__('The request data is invalid.'));\n        }\n        if (!Validation::uuid($privateKeyId)) {\n            throw new BadRequestException(__('The request data is invalid.'));\n        }\n\n        /** @var \\Passbolt\\Metadata\\Model\\Table\\MetadataPrivateKeysTable $metadataPrivateKeysTable */\n        $metadataPrivateKeysTable = $this->fetchTable('Passbolt/Metadata.MetadataPrivateKeys');\n        try {\n            /** @var \\Passbolt\\Metadata\\Model\\Entity\\MetadataPrivateKey $metadataPrivateKey */\n            $metadataPrivateKey = $metadataPrivateKeysTable\n                ->find()\n                ->where(['user_id' => $uac->getId(), 'id ' => $privateKeyId])\n                ->firstOrFail();\n        } catch (RecordNotFoundException $exception) {\n            throw new NotFoundException(__('The metadata private key does not exist or has been deleted.'));\n        }\n\n        if ($metadataPrivateKey->modified_by === $uac->getId()) {\n            throw new BadRequestException(__('The metadata private key was already edited by the user.'));\n        }\n\n        $metadataPrivateKeysTable->patchEntity($metadataPrivateKey, [\n            'data' => $data['data'],\n            'modified_by' => $uac->getId(),\n        ], [\n            'accessibleFields' => [\n                'data' => true,\n                'modified_by' => true,\n            ],\n        ]);\n        if (!empty($metadataPrivateKey->getErrors())) {\n            $this->handleValidationErrors($metadataPrivateKey, $metadataPrivateKeysTable);\n        }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Service/MetadataPrivateKeysUpdateService.php#L47-L83","documentation":"NotFoundException thrown when no metadata private key row matches both the given ID and the current user (user_id = uac id). firstOrFail() raises RecordNotFoundException which the service converts to a 404. Note the query scopes by user, so a key that exists but belongs to another user also yields 404.","triggerScenarios":"PUT to a metadata private key ID that does not exist, was deleted, or belongs to a different user than the authenticated one.","commonSituations":"Stale client cache referencing a deleted key; using another user's key ID; a typo'd UUID; the key was removed during metadata key rotation.","solutions":["Confirm the key ID exists via GET on the metadata private keys collection first.","Ensure the authenticated user is the owner of the key; only owners can update their private keys.","Refresh the local cache of metadata private keys if records were deleted elsewhere."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"const key = await api.get(`/metadata/private-keys/${id}`); // 404 here means no retry needed\nif (key.userId !== currentUserId) throw new Error('not the owner');","typeGuard":null,"tryCatchPattern":"catch (NotFoundException) { // 404\n  // refresh local cache; do not retry with the same ID\n  await refreshMetadataPrivateKeys();\n}","preventionTips":["Fetch the key before updating to confirm existence and ownership","Only update keys owned by the authenticated user","Invalidate caches when keys are deleted or rotated"],"tags":["not-found","metadata","php"],"backgroundTag":"resource-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"}