{"record":{"id":"8eaf4f7cc711e132","repo":"passbolt/passbolt_api","slug":"could-not-save-the-entity-history","errorCode":null,"errorMessage":"Could not save the entity history.","messagePattern":"Could not save the entity history\\.","errorType":"exception","errorClass":"InternalErrorException","httpStatus":500,"severity":"error","filePath":"plugins/PassboltCe/Log/src/Model/Table/EntitiesHistoryTable.php","lineNumber":212,"sourceCode":"        ];\n        $data = array_merge($defaultData, $data);\n\n        // Check validation rules.\n        $log = $this->buildEntity($data);\n        if ($log->getErrors()) {\n            throw new ValidationException(__('Could not validate entity history data.', true), $log, $this);\n        }\n\n        $entityHistory = $this->save($log, ['associated' => ['PermissionsHistory']]);\n\n        // Check for validation errors. (associated models too).\n        if ($log->getErrors()) {\n            throw new ValidationException(__('Could not validate entity history data.'), $entityHistory, $this);\n        }\n\n        // Check for errors while saving.\n        if (!$entityHistory) {\n            throw new InternalErrorException('Could not save the entity history.');\n        }\n\n        return $entityHistory;\n    }\n}\n","sourceCodeStart":194,"sourceCodeEnd":218,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Log/src/Model/Table/EntitiesHistoryTable.php#L194-L218","documentation":"EntitiesHistoryTable::create() throws this InternalErrorException when save() returns false without validation errors — a raw persistence failure. The entity history row could not be written to the database even though the data was valid.","triggerScenarios":"Valid entity history data but the INSERT fails: DB connection loss, missing entity_history table/columns after partial migration, lock wait timeout, or a beforeSave listener aborting silently.","commonSituations":"Migrations missing after a passbolt upgrade; database under heavy load during bulk operations that write many history rows; replication/readonly connection misconfiguration; disk-full on the DB host.","solutions":["Check application and database error logs for the underlying save failure cause.","Run pending migrations so the entity history schema matches the plugin version.","Verify DB connectivity and that the connection is not read-only.","Audit event listeners on Model.beforeSave for EntitiesHistory that may return false without errors."],"exampleFix":"// before\n$entityHistory = $this->save($log, ['associated' => ['PermissionsHistory']]);\nif (!$entityHistory) {\n    throw new InternalErrorException('Could not save the entity history.');\n}\n// after\n$entityHistory = $this->save($log, ['associated' => ['PermissionsHistory']]);\nif (!$entityHistory) {\n    $this->log('Entity history save failed: ' . json_encode($log->getErrors()), 'error');\n    throw new InternalErrorException('Could not save the entity history.');\n}","handlingStrategy":"try-catch","validationCode":"try { $this->EntitiesHistory->getConnection()->query('SELECT 1'); } catch (\\Throwable $e) { // DB unavailable }","typeGuard":"null","tryCatchPattern":"try { $entitiesHistoryTable->create($data); } catch (InternalErrorException $e) { Log::error('Entity history save failed: ' . $e->getMessage()); // degrade gracefully, do not fail the main operation\n}","preventionTips":["Run migrations on every deployment.","Monitor DB locks and long-running transactions during bulk operations.","Avoid wrapping many history writes in one long transaction.","Audit beforeSave listeners for silent false returns."],"tags":["database","logging","persistence","cakephp"],"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"}