{"record":{"id":"3b9927b4cac7c26b","repo":"passbolt/passbolt_api","slug":"could-not-create-the-resource-folder-relation-please-try","errorCode":null,"errorMessage":"Could not create the resource folder relation, please try again later.","messagePattern":"Could not create the resource folder relation, please try again later\\.","errorType":"exception","errorClass":"Cake\\Http\\Exception\\InternalErrorException","httpStatus":500,"severity":"critical","filePath":"plugins/PassboltCe/Folders/src/Service/Resources/ResourcesAfterCreateService.php","lineNumber":91,"sourceCode":"        if (!is_null($folderParentId)) {\n            $this->validateParentFolder($uac, $resource, $folderParentId);\n            if ($resource->hasErrors()) {\n                return;\n            }\n        }\n\n        $folderRelationData = [\n            'foreign_model' => FoldersRelation::FOREIGN_MODEL_RESOURCE,\n            'foreign_id' => $resource->id,\n            'folder_parent_id' => $folderParentId,\n            'user_id' => $uac->getId(),\n        ];\n\n        try {\n            $this->foldersRelationsCreateService->create($folderRelationData);\n            $resource->set('folder_parent_id', $folderParentId);\n        } catch (Exception $e) {\n            throw new InternalErrorException(\n                'Could not create the resource folder relation, please try again later.',\n                500,\n                $e\n            );\n        }\n    }\n\n    /**\n     * Validate the parent folder\n     *\n     * @param \\App\\Utility\\UserAccessControl $uac The current user\n     * @param \\App\\Model\\Entity\\Resource $resource The created resource.\n     * @param string|null $folderParentId The parent folder to validate\n     * @return void\n     * @throws \\App\\Error\\Exception\\CustomValidationException If the parent folder does not exist.\n     * @throws \\Cake\\Http\\Exception\\ForbiddenException If the user is not allowed to insert content in the parent folder.\n     */\n    private function validateParentFolder(","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Folders/src/Service/Resources/ResourcesAfterCreateService.php#L73-L109","documentation":"After a resource is created, ResourcesAfterCreateService tries to insert the resource's folder relation (its personal-tree entry). If FoldersRelationsCreateService->create() throws any Exception, it is wrapped in InternalErrorException 'Could not create the resource folder relation, please try again later.' This is an internal persistence failure, not a client data problem.","triggerScenarios":"Creating a resource when the folders_relations insert fails — e.g. invalid/missing folder_parent_id FK, database connection failure, constraint violation, or the parent folder relation row missing for the creating user.","commonSituations":"Database outages or lock timeouts during resource creation; corrupted personal folder trees after failed migrations; passing a folder_parent_id of a folder the user has no relation to; concurrency conflicts on folders_relations rows.","solutions":["Retry the resource creation as the message suggests — transient DB issues often resolve on retry.","Check the previous exception (chained in the logs) for the root cause: FK violation, connection error, duplicate key, etc.","Verify folder_parent_id, if provided, references an existing folder the creating user can access.","Run folder tree repair (e.g. the folders repair/consistency commands) if personal trees are corrupted.","Check database health and migration status (ddev refresh / migrations) if it reproduces."],"exampleFix":"// before: creating with a parent the user has no relation to\nawait createResource({ name: 'pw', folder_parent_id: otherUsersFolderId });\n\n// after: use a folder the creator can access, or omit parent\nawait createResource({ name: 'pw', folder_parent_id: myOwnFolderId });","handlingStrategy":"retry","validationCode":"if (folderParentId && !userFolders.some(f => f.id === folderParentId)) throw new Error('Parent folder not accessible');","typeGuard":null,"tryCatchPattern":"try { await createResource(data); } catch (e) { if (/folder relation/.test(e.message)) { await sleep(backoff); return createResource(data); } throw e; }","preventionTips":["Retry transient failures with backoff before surfacing to the user.","Only pass folder_parent_id values the creating user has a relation to.","Run folder-tree consistency/repair commands after failed migrations.","Monitor database health and lock timeouts on the server."],"tags":["folders","database","internal-error","resource-creation"],"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"}