passbolt/passbolt_api · error · ValidationException
Could not validate directory entry data.
Error message
Could not validate directory entry data.
What it means
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.
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
Example fix
// before: missing directory_name $entriesTable->create(['foreign_model' => 'User']); // after: required fields provided $entriesTable->create(['foreign_model' => 'User', 'directory_name' => 'cn=jdoe,ou=people,dc=example,dc=com', 'directory_id' => $dirId]);
Defensive patterns
Strategy: validation
Validate before calling
// validate entry data before create
foreach (['directory_name', 'foreign_model', 'directory_id'] as $f) {
if (empty($data[$f])) {
throw new \InvalidArgumentException("Missing required field: $f");
}
} Type guard
$entity = $entriesTable->buildEntityFromData($data);
if (!empty($entity->getErrors())) {
var_export($entity->getErrors()); // fix fields before calling create()
return;
} Try / catch
try {
$entriesTable->create($data);
} catch (ValidationException $e) {
$this->log(json_encode($e->getEntity()->getErrors()), 'error');
} Prevention
- 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
When it happens
Trigger: updateOrCreate() -> create() invoked during sync with LDAP data that violates DirectoryEntry rules: empty directory_name, invalid 'foreign_model' value, id/fingerprint format issues.
Common situations: 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.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- group(s) returned by your directory are invalid and will be…
- users returned by your directory are invalid and will be…
- Could not validate user data.
- $exception->getMessage()
- $message
AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17).
Data as JSON: /api/errors/94a769029d1006af.
Report an issue: GitHub.
Appendix: source
Thrown at plugins/PassboltEe/DirectorySync/src/Model/Table/DirectoryEntriesTable.php:226
}
$directoryEntry = $this->buildEntity($data);
return $directoryEntry;
}
/**
* Create a new directory entry.
*
* @param array $data data
* @return \Passbolt\DirectorySync\Model\Entity\DirectoryEntry|bool
*/
public function create(array $data): bool|DirectoryEntry
{
// Check validation rules.
$directoryEntry = $this->buildEntityFromData($data);
if (!empty($directoryEntry ->getErrors())) {
throw new ValidationException(__('Could not validate directory entry data.'), $directoryEntry, $this);
}
$de = $this->save($directoryEntry);
// Check for validation errors. (associated models too).
if (!empty($directoryEntry->getErrors())) {
throw new ValidationException(__('Could not validate directory entry data.'), $directoryEntry, $this);
}
// Check for errors while saving.
if (!$de) {
throw new InternalErrorException('Could not save the directory entry.');
}
return $de;
}
/**View on GitHub (pinned to 31c1bbc10f)