{"record":{"id":"0558d53d2583813b","repo":"passbolt/passbolt_api","slug":"this-record-is-already-marked-as-to-be-ignored","errorCode":null,"errorMessage":"This record is already marked as to be ignored.","messagePattern":"This record is already marked as to be ignored\\.","errorType":"http","errorClass":"BadRequestException","httpStatus":400,"severity":"warning","filePath":"plugins/PassboltEe/DirectorySync/src/Model/Table/DirectoryIgnoreTable.php","lineNumber":195,"sourceCode":"    /**\n     * Create or fail\n     *\n     * @param string $foreignModel foreign model\n     * @param string $foreignKey foreign key\n     * @return \\Passbolt\\DirectorySync\\Model\\Entity\\DirectoryIgnore|bool\n     * @throws \\Cake\\Http\\Exception\\BadRequestException if the $foreignKey is not a valid UUID\n     */\n    public function createOrFail(string $foreignModel, string $foreignKey): bool|DirectoryIgnore\n    {\n        if (!Validation::uuid($foreignKey)) {\n            throw new BadRequestException(__('The identifier should be a valid UUID.'));\n        }\n        try {\n            $entry = $this->get($foreignKey);\n        } catch (RecordNotFoundException $exception) {\n        }\n        if (isset($entry)) {\n            throw new BadRequestException(__('This record is already marked as to be ignored.'));\n        }\n\n        $ignore = $this->newEntity(\n            [\n                'id' => $foreignKey,\n                'foreign_model' => $foreignModel,\n            ],\n            [\n                'accessibleFields' => [\n                    'id' => true,\n                    'foreign_model' => true,\n                ]]\n        );\n        if ($ignore->getErrors()) {\n            throw new ValidationException(__('This is not a valid record to ignore.'), $ignore, $this);\n        }\n        $this->checkRules($ignore);\n        if ($ignore->getErrors()) {","sourceCodeStart":177,"sourceCodeEnd":213,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/DirectorySync/src/Model/Table/DirectoryIgnoreTable.php#L177-L213","documentation":"DirectoryIgnoreTable::createOrFail is called when passbolt's directory sync needs to permanently ignore a record (a user or group so it won't be synced). Before creating the ignore entry it first checks whether an ignore entry with the same primary key already exists; if it does, it throws this BadRequestException instead of silently duplicating the ignore. It is a guard against re-ignoring an already ignored record.","triggerScenarios":"Calling DirectoryIgnoreTable::createOrFail($foreignModel, $foreignKey) (e.g. via the directory sync 'ignore user/group' endpoints or sync actions) when a directory_ignore row with id == $foreignKey already exists in the database.","commonSituations":"Clicking 'ignore' twice in the directory sync UI or replaying an ignore request; a sync job retrying after a previous ignore succeeded; stale client state where the UI still shows the record as ignorable; two admins ignoring the same user concurrently.","solutions":["Check existence before calling: if ($this->DirectoryIgnore->exists(['id' => $foreignKey])) skip or return the existing entry instead of calling createOrFail.","Catch BadRequestException in the caller and treat it as success (the record is already ignored, which is the desired end state).","Refresh the sync results UI so already-ignored records are no longer offered for ignore.","If the ignore is stale, delete the existing directory_ignore row (DirectoryIgnoreTable::deleteAll) then retry."],"exampleFix":"// before\n$this->DirectoryIgnore->createOrFail('User', $userId);\n// after\nif (!$this->DirectoryIgnore->exists(['id' => $userId])) {\n    $this->DirectoryIgnore->createOrFail('User', $userId);\n}","handlingStrategy":"try-catch","validationCode":"$alreadyIgnored = $this->DirectoryIgnore->exists(['id' => $recordId]);\nif ($alreadyIgnored) { /* skip or return early */ }","typeGuard":"$isIgnored = fn(string $id): bool => $this->DirectoryIgnore->exists(['id' => $id]);","tryCatchPattern":"try {\n    $this->DirectoryIgnore->createOrFail('User', $userId);\n} catch (Cake\\Http\\Exception\\BadRequestException $e) {\n    // already ignored — treat as success / idempotent no-op\n}","preventionTips":["Check existence with exists(['id' => $foreignKey]) before calling createOrFail","Make ignore operations idempotent in callers by catching BadRequestException","Keep sync-results UI state in sync so ignored records aren't re-offered","Serialize ignore operations to avoid concurrent duplicate requests"],"tags":["passbolt","directory-sync","duplicate-record","http-400"],"backgroundTag":"record-already-exists","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"}