{"record":{"id":"20a158ad7463b79c","repo":"passbolt/passbolt_api","slug":"an-unexpected-error-occurred-while-creating-the-user-in-the","errorCode":null,"errorMessage":"An unexpected error occurred while creating the user in the database","messagePattern":"An unexpected error occurred while creating the user in the database","errorType":"exception","errorClass":"Passbolt\\Scim\\Exception\\ConflictException","httpStatus":409,"severity":"error","filePath":"plugins/PassboltEe/Scim/src/Utility/Resource/UserScimResource.php","lineNumber":439,"sourceCode":"     * Create a ScimEntry linking the user to the SCIM resource.\n     *\n     * @param \\App\\Model\\Entity\\User $user\n     * @throws \\Passbolt\\Scim\\Exception\\ConflictException\n     */\n    private function createScimEntry(User $user): void\n    {\n        /** @var \\Passbolt\\Scim\\Model\\Entity\\ScimEntry $scimEntry */\n        $scimEntry = $this->ScimEntries->buildEntity([\n            'scim_name' => $this->userName,\n            'external_identifier' => $this->externalId,\n            'foreign_model' => ScimEntry::FOREIGN_MODEL_USERS,\n            'foreign_key' => $user->id,\n        ]);\n        if (!$this->ScimEntries->save($scimEntry, ['lockForUpdate' => true])) {\n            Log::error('Unable to save the scim entity');\n            $this->logScimDebug('createScimEntry', $scimEntry);\n\n            throw new ConflictException(\n                __('An unexpected error occurred while creating the user in the database'),\n                scimType: ScimException::SCIM_TYPE_INVALID_VALUE,\n            );\n        }\n    }\n\n    /**\n     * @return \\App\\Model\\Entity\\User|null\n     */\n    protected function getScimSettingsSelectedUser(): ?User\n    {\n        $scimConfig = (new ScimGetSettingsService())->getSettingsDecryptedValue();\n        if (empty($scimConfig['scim_user_id'])) {\n            return null;\n        }\n\n        /** @var \\App\\Model\\Entity\\User|null $user */\n        $user = $this->Users","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/Scim/src/Utility/Resource/UserScimResource.php#L421-L457","documentation":"Thrown by createScimEntry() when the ScimEntries save fails after the user record was created, inside the create() transaction. Since the whole operation is wrapped in a transactional closure, failure here rolls back the user creation; the message is intentionally vague while details go to Log::error and logScimDebug.","triggerScenarios":"POST /scim/v2/Users where building/saving the scim_entry fails — e.g. duplicate external_identifier or scim_name violating unique constraints, missing externalId, or a lock contention failure on the scim_entries table.","commonSituations":"Two IdPs or two concurrent sync runs provisioning the same externalId, externalId reuse after deleting a SCIM user without purging scim_entries, or database unique-index violations.","solutions":["Check passbolt error logs and the logScimDebug output for the exact save failure reason","Ensure externalId is unique and non-empty across SCIM resources; fix the IdP mapping if it reuses ids","Purge orphaned/stale scim_entries rows (e.g. after re-provisioning) then retry the create"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"if (empty($payload['externalId'])) {\n    throw new InvalidArgumentException('externalId is required for SCIM user creation.');\n}\n$duplicate = TableRegistry::getTableLocator()->get('Passbolt/Scim.ScimEntries')\n    ->find()->where(['external_identifier' => $payload['externalId']])->first();\nif ($duplicate) {\n    throw new RuntimeException('externalId already provisioned; PATCH instead of POST.');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $scimUsers->create();\n} catch (\\Passbolt\\Scim\\Exception\\ConflictException $e) {\n    if ($e->getMessage() === 'An unexpected error occurred while creating the user in the database') {\n        // check error log + logScimDebug output for the save failure, then retry\n    }\n}","preventionTips":["Guarantee externalId uniqueness across the IdP before creating resources","Clean orphaned scim_entries after re-provisioning or restores","Watch passbolt logs (\"Unable to save the scim entity\") for lock/unique-index failures"],"tags":["scim","database","write-failure"],"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"}