{"record":{"id":"527d7ecddb859fb4","repo":"passbolt/passbolt_api","slug":"the-rbacs-could-not-be-saved","errorCode":null,"errorMessage":"The rbacs could not be saved.","messagePattern":"The rbacs could not be saved\\.","errorType":"validation","errorClass":"CustomValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltCe/Rbacs/src/Event/CreateRbacsOnRoleCreateListener.php","lineNumber":103,"sourceCode":"                ['accessibleFields' => [\n                    'role_id' => true,\n                    'control_function' => true,\n                    'foreign_model' => true,\n                    'foreign_id' => true,\n                    'created' => true,\n                    'modified' => true,\n                    'created_by' => true,\n                    'modified_by' => true,\n                ]]\n            );\n        }\n\n        try {\n            $rbacsTable->saveManyOrFail($entities);\n        } catch (PersistenceFailedException $e) {\n            $errors = $e->getEntity()->getErrors();\n\n            throw new CustomValidationException(\n                __('The rbacs could not be saved.'),\n                $errors\n            );\n        } catch (Exception $e) {\n            throw new InternalErrorException(__('Could not save the rbacs, please try again later.'), null, $e);\n        }\n    }\n}\n","sourceCodeStart":85,"sourceCodeEnd":112,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Rbacs/src/Event/CreateRbacsOnRoleCreateListener.php#L85-L112","documentation":"Thrown by CreateRbacsOnRoleCreateListener::createRbacsOnRoleCreate() when saveManyOrFail on the RBAC entities fails with a PersistenceFailedException, re-raised as a CustomValidationException carrying the entity errors. It means one or more of the per-role default RBAC rows violated model/validation rules.","triggerScenarios":"Role-created event fires and the generated RBAC entities fail validation during save (e.g. invalid control_function, duplicate uniqueness constraint, missing required field).","commonSituations":"Corrupted or partially migrated rbacs table causing uniqueness conflicts, plugin registering UI actions whose names conflict with existing rbacs rows, or database state left inconsistent after a failed upgrade.","solutions":["Read the CustomValidationException's errors payload to identify which rbac entities/fields failed.","Check the rbacs table for duplicate rows for the new role and clean them up.","Re-run migrations so the rbacs schema and default rows are consistent.","Retry role creation after fixing the conflicting data."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"foreach ($entities as $entity) {\n    if ($entity->getErrors()) {\n        throw new InvalidArgumentException('Invalid rbac entity: ' . json_encode($entity->getErrors()));\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    $rbacsTable->saveManyOrFail($entities);\n} catch (PersistenceFailedException $e) {\n    $errors = $e->getEntity()->getErrors();\n    // inspect and repair conflicting rbacs rows\n}","preventionTips":["Keep the rbacs table free of duplicate rows (uniqueness on role_id + control_function).","Run all migrations after upgrades.","Avoid creating roles concurrently with rbacs regeneration jobs.","Log entity errors at save time to diagnose conflicts quickly."],"tags":["php","cakephp","rbacs","persistence","validation"],"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"}