{"record":{"id":"94a769029d1006af","repo":"passbolt/passbolt_api","slug":"could-not-validate-directory-entry-data","errorCode":null,"errorMessage":"Could not validate directory entry data.","messagePattern":"Could not validate directory entry data\\.","errorType":"validation","errorClass":"ValidationException","httpStatus":400,"severity":"error","filePath":"plugins/PassboltEe/DirectorySync/src/Model/Table/DirectoryEntriesTable.php","lineNumber":226,"sourceCode":"        }\n\n        $directoryEntry = $this->buildEntity($data);\n\n        return $directoryEntry;\n    }\n\n    /**\n     * Create a new directory entry.\n     *\n     * @param array $data data\n     * @return \\Passbolt\\DirectorySync\\Model\\Entity\\DirectoryEntry|bool\n     */\n    public function create(array $data): bool|DirectoryEntry\n    {\n        // Check validation rules.\n        $directoryEntry = $this->buildEntityFromData($data);\n        if (!empty($directoryEntry ->getErrors())) {\n            throw new ValidationException(__('Could not validate directory entry data.'), $directoryEntry, $this);\n        }\n\n        $de = $this->save($directoryEntry);\n\n        // Check for validation errors. (associated models too).\n        if (!empty($directoryEntry->getErrors())) {\n            throw new ValidationException(__('Could not validate directory entry data.'), $directoryEntry, $this);\n        }\n\n        // Check for errors while saving.\n        if (!$de) {\n            throw new InternalErrorException('Could not save the directory entry.');\n        }\n\n        return $de;\n    }\n\n    /**","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltEe/DirectorySync/src/Model/Table/DirectoryEntriesTable.php#L208-L244","documentation":"ValidationException thrown by DirectoryEntriesTable::create() when the freshly built DirectoryEntry entity (buildEntityFromData) already carries validation errors before saving. The directory entry (LDAP record mirror) failed the table's validation rules, e.g. invalid foreign model, missing directory_name, or oversized/truncated DN fields.","triggerScenarios":"updateOrCreate() -> create() invoked during sync with LDAP data that violates DirectoryEntry rules: empty directory_name, invalid 'foreign_model' value, id/fingerprint format issues.","commonSituations":"LDAP DNs containing characters that break normalization; sync of entries whose foreign model mapping (User/Group) is misconfigured; DN truncation to DN_MAX_LENGTH producing data that still fails other rules.","solutions":["Inspect the ValidationException's entity errors ($e->getEntity()->getErrors()) to see which fields failed","Verify the LDAP attributes mapped to directory_name and foreign_model produce valid values","Ensure the sync report maps entries to the correct foreign model ('User' or 'Group')","Check for DB schema drift (run migrations) that could make rules mismatch stored data"],"exampleFix":"// before: missing directory_name\n$entriesTable->create(['foreign_model' => 'User']);\n// after: required fields provided\n$entriesTable->create(['foreign_model' => 'User', 'directory_name' => 'cn=jdoe,ou=people,dc=example,dc=com', 'directory_id' => $dirId]);","handlingStrategy":"validation","validationCode":"// validate entry data before create\nforeach (['directory_name', 'foreign_model', 'directory_id'] as $f) {\n    if (empty($data[$f])) {\n        throw new \\InvalidArgumentException(\"Missing required field: $f\");\n    }\n}","typeGuard":"$entity = $entriesTable->buildEntityFromData($data);\nif (!empty($entity->getErrors())) {\n    var_export($entity->getErrors()); // fix fields before calling create()\n    return;\n}","tryCatchPattern":"try {\n    $entriesTable->create($data);\n} catch (ValidationException $e) {\n    $this->log(json_encode($e->getEntity()->getErrors()), 'error');\n}","preventionTips":["Always inspect entity errors from the exception before retrying","Ensure LDAP attributes mapped to directory_name are non-empty and normalized","Map entries to the correct foreign_model ('User' or 'Group')","Run migrations after plugin upgrades to keep rules and schema aligned"],"tags":["validation","ldap","directory-sync","entity"],"backgroundTag":"schema-validation-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"}