{"record":{"id":"4ddd52881a9703e5","repo":"passbolt/passbolt_api","slug":"could-not-validate-folders-relations-history-data","errorCode":null,"errorMessage":"Could not validate folders relations history data.","messagePattern":"Could not validate folders relations history data\\.","errorType":"validation","errorClass":"Cake\\Web\\Exception\\ValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Folders/src/Model/Table/FoldersRelationsHistoryTable.php","lineNumber":167,"sourceCode":"            ],\n        ]);\n    }\n\n    /**\n     * Create a new FoldersRelationHistory.\n     *\n     * @param array $data the data\n     * @return \\Passbolt\\Folders\\Model\\Entity\\FoldersRelation\n     * @throws \\App\\Error\\Exception\\ValidationException\n     * @throws \\Cake\\Http\\Exception\\InternalErrorException\n     */\n    public function create(array $data): FoldersRelation\n    {\n        // Check validation rules.\n        $folderRelationHistory = $this->buildEntity($data);\n        if ($folderRelationHistory->getErrors()) {\n            $msg = __('Could not validate folders relations history data.');\n            throw new ValidationException($msg, $folderRelationHistory, $this);\n        }\n        $folderRelationHistory = $this->save($folderRelationHistory);\n\n        // Check for errors while saving.\n        if (!$folderRelationHistory) {\n            throw new InternalErrorException('Could not save the folder relation history.');\n        }\n\n        // Check for validation errors. (associated models too).\n        if ($folderRelationHistory->getErrors()) {\n            $msg = __('Could not validate folders relations history data.');\n            throw new ValidationException($msg, $folderRelationHistory, $this);\n        }\n\n        return $folderRelationHistory;\n    }\n}\n","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Folders/src/Model/Table/FoldersRelationsHistoryTable.php#L149-L185","documentation":"Thrown by FoldersRelationsHistoryTable::create() when the FoldersRelation history entity returned by buildEntity() already contains validation errors before any save attempt. It means the input data (foreign model ids, user id, etc.) broke the table's validation rules.","triggerScenarios":"Calling create() with data failing validation rules — invalid or missing folder_parent_id/folder_foreign_id/user_id (non-UUID values), or an empty data array.","commonSituations":"Passing null or malformed identifiers when recording parent-child folder relation history; upgrading code between plugin versions where validation rules were tightened; association validation failures against Users or Folders tables.","solutions":["Log/inspect the ValidationException errors payload to identify the offending field.","Validate that all ids are valid UUIDs and reference existing entities before calling create().","Fix the calling service so it never passes null parent/foreign ids when recording relation history.","Catch ValidationException and handle gracefully in the move/rename workflow."],"exampleFix":"// before\n$foldersRelationsHistoryTable->create(['folder_parent_id' => $parentId ?? null]);\n// after\nif ($parentId !== null && !Uuid::isValid($parentId)) { throw new InvalidArgumentException('Invalid parent id'); }\n$foldersRelationsHistoryTable->create(['folder_parent_id' => $parentId]);","handlingStrategy":"validation","validationCode":"foreach (['folder_parent_id','folder_foreign_id','user_id'] as $key) {\n  if (isset($data[$key]) && !Uuid::isValid($data[$key])) { throw new InvalidArgumentException(\"Invalid $key\"); }\n}","typeGuard":"$validIds = fn(array $data): bool => collect($data)->every(fn($v, $k) => !str_contains($k, 'id') || $v === null || Uuid::isValid($v));","tryCatchPattern":"try { $table->create($data); } catch (ValidationException $e) { foreach ($e->getErrors() as $field => $errs) { /* log */ } }","preventionTips":["Never pass null parent/foreign ids when the relation expects one","Validate ids against the DB before writing relation history","Keep plugin migrations current so validation rules match schema"],"tags":["validation","folders","relations"],"backgroundTag":"schema-validation-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"}