{"record":{"id":"ec09ad49fda5e650","repo":"passbolt/passbolt_api","slug":"could-not-save-the-secret-access","errorCode":null,"errorMessage":"Could not save the secret access.","messagePattern":"Could not save the secret access\\.","errorType":"exception","errorClass":"InternalErrorException","httpStatus":500,"severity":"error","filePath":"plugins/PassboltCe/Log/src/Model/Table/SecretAccessesTable.php","lineNumber":177,"sourceCode":"            'secret_id' => $secretId,\n        ];\n\n        // Check validation rules.\n        $secretAccess = $this->buildEntity($data);\n        if ($secretAccess->getErrors()) {\n            throw new ValidationException(__('Could not validate secret access data.', true), $secretAccess, $this);\n        }\n\n        $secretAccessSaved = $this->save($secretAccess);\n\n        // Check for validation errors. (associated models too).\n        if ($secretAccess->getErrors()) {\n            throw new ValidationException(__('Could not validate secret access data.'), $secretAccess, $this);\n        }\n\n        // Check for errors while saving.\n        if (!$secretAccessSaved) {\n            throw new InternalErrorException('Could not save the secret access.');\n        }\n\n        return $secretAccessSaved;\n    }\n}\n","sourceCodeStart":159,"sourceCodeEnd":183,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltCe/Log/src/Model/Table/SecretAccessesTable.php#L159-L183","documentation":"Thrown by SecretAccessesTable::createFromSecretDetails() when save() returns false after validation succeeded — meaning the INSERT into secret_accesses failed at the persistence layer (constraint, lock, connection, or an event listener returning false).","triggerScenarios":"$this->save($secretAccess) returning falsy: database constraint violation on secret_accesses (bad secret_id/user_id foreign keys), table missing after skipped migration, transaction rollback, or a Model.event listener aborting the save.","commonSituations":"Secret deleted concurrently by another request, missing secret_accesses table (migration not run), database disk-full/replication issues, and schema mismatch after partial plugin upgrades.","solutions":["Confirm the secret_id and user_id exist in secrets/users tables at save time","Run passbolt migrate to ensure the secret_accesses table schema is current","Inspect database/error logs for the underlying SQL error and fix the constraint","Retry the operation if the failure was transient (lock timeout, dead connection)"],"exampleFix":"// before\n$this->SecretAccesses->createFromSecretDetails($userId, $secretId, $secret, $created); // may 500\n// after\n$secretExists = $this->Secrets->exists(['id' => $secretId]);\nif (!$secretExists) {\n    throw new BadRequestException(__('The secret does not exist.'));\n}\n$this->SecretAccesses->createFromSecretDetails($userId, $secretId, $secret, $created);","handlingStrategy":"try-catch","validationCode":"$secretExists = $this->Secrets->exists(['id' => $secretId]);\n$userExists = $this->Users->exists(['id' => $userId]);\nif (!$secretExists || !$userExists) { throw new BadRequestException(...); }","typeGuard":"if (!($secret instanceof \\App\\Model\\Entity\\Secret && $secret->id)) { throw new \\InvalidArgumentException('Persisted secret required'); }","tryCatchPattern":"try {\n    $this->SecretAccesses->createFromSecretEntity($user, $secret);\n} catch (\\Cake\\Http\\Exception\\InternalErrorException $e) {\n    $this->log('Secret access save failed: ' . $e->getMessage());\n    // check DB logs, migrate if schema drift, retry once if transient\n}","preventionTips":["Keep schema current with passbolt migrate","Verify referenced secret/user rows exist before logging","Monitor DB error logs for secret_accesses constraint failures","Avoid hard-deleting secrets while audit logging is in flight"],"tags":["database","persistence","orm"],"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-21T09:17:21.228Z"}