{"record":{"id":"3c09c7db0385447d","repo":"passbolt/passbolt_api","slug":"the-metadata-private-keys-could-not-be-created","errorCode":null,"errorMessage":"The metadata private keys could not be created.","messagePattern":"The metadata private keys could not be created\\.","errorType":"exception","errorClass":"InternalErrorException","httpStatus":500,"severity":"critical","filePath":"plugins/PassboltCe/Metadata/src/Service/MetadataPrivateKeysCreateService.php","lineNumber":186,"sourceCode":"     */\n    public function createMany(UserAccessControl $uac, MetadataPrivateKeysCreateManyDto $dto): void\n    {\n        $uac->assertIsAdmin();\n        if (empty($dto->getData())) {\n            return;\n        }\n\n        $entities = $this->buildEntities($uac, $dto);\n\n        /** @var \\Passbolt\\Metadata\\Model\\Table\\MetadataPrivateKeysTable $metadataPrivateKeysTable */\n        $metadataPrivateKeysTable = $this->fetchTable('Passbolt/Metadata.MetadataPrivateKeys');\n\n        try {\n            $metadataPrivateKeysTable->saveManyOrFail($entities);\n        } catch (PersistenceFailedException $exception) { // @phpstan-ignore-line\n            $this->handleSaveManyValidationException($exception, $entities);\n        } catch (Exception $exception) {\n            throw new InternalErrorException(\n                __('The metadata private keys could not be created.'),\n                null,\n                $exception\n            );\n        }\n    }\n\n    /**\n     * Create an array of metadata private entities from given data.\n     * The exception will be thrown on first validation error occurrence.\n     *\n     * @param \\App\\Utility\\UserAccessControl $uac User access control.\n     * @param \\Passbolt\\Metadata\\Model\\Dto\\MetadataPrivateKeysCreateManyDto $dto DTO to get data from.\n     * @return array\n     * @throws \\App\\Error\\Exception\\CustomValidationException When there are validation errors\n     */\n    protected function buildEntities(UserAccessControl $uac, MetadataPrivateKeysCreateManyDto $dto): array\n    {","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Metadata/src/Service/MetadataPrivateKeysCreateService.php#L168-L204","documentation":"In createMany, after handleSaveManyValidationException, any other Exception escaping saveManyOrFail is rethrown as an InternalErrorException with this generic message and the original exception chained. It means batch persistence of metadata private keys failed for a non-validation reason.","triggerScenarios":"saveManyOrFail throws — DB connection loss, deadlock/lock timeout, constraint violation outside validation, or transaction failure while saving many entities at once.","commonSituations":"Bulk share of a metadata key to many users hitting DB timeouts; database failover mid-transaction; oversized batch triggering lock contention.","solutions":["Inspect the chained exception in server logs for the root cause","Retry the batch; split it into smaller batches if timeouts occur","Verify DB health (connections, locks, disk) before retrying","Fix any underlying constraint conflicts (e.g. duplicates within the batch)"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"catch (e) { if (e.response?.status === 500 && /private keys could not be created/.test(e.response?.body?.message)) { await backoff(); return createInSmallerBatches(items); } throw e; }","preventionTips":["Keep batches small to reduce lock contention and timeouts","Check server logs for the chained exception","Validate all batch items before submitting to avoid partial-work complexity"],"tags":["http-500","database","batch","persistence"],"backgroundTag":"database-write-failed","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"}