passbolt/passbolt_api · error
Data " " from " " could not be inserted
Error message
Data "%s" from "%s" could not be inserted
What it means
SaveEntity is a save strategy used by TestData seed commands: it loops over rows and saves each entity. If saveEntity() throws for a row, it prints 'Data "<row-id>" from "<entity>" could not be inserted', dumps the failing row, logs the exception message as a warning, and aborts the loop by returning false. It reports per-row insert failures during seeding.
Solutions
- Read the exception warning printed right after this error for the root cause.
- Inspect the printed row dump to find the offending field.
- Clean conflicting data (duplicate ids/emails) or use fresh fixtures.
- Run `bin/cake migrations migrate` if the schema is behind.
- Re-run the seed command after fixing.
Example fix
// before
$this->shell->io->err(sprintf('Data "%s" from "%s" could not be inserted', $row['id'], $this->shell->entityName)); //phpcs:ignore
// after
$this->shell->io->err(sprintf('Data "%s" from "%s" could not be inserted: %s', $row['id'], $this->shell->entityName, $e->getMessage())); //phpcs:ignore Defensive patterns
Strategy: validation
Validate before calling
// before saving a row
$errors = $table->newEntity($row)->getErrors();
if ($errors) {
var_dump($errors); // fix row before insert
return false;
} Type guard
function isSaveableRow(array $row): bool {
return isset($row['id']) && is_string($row['id']) && $row['id'] !== '';
} Try / catch
try {
$this->saveEntity($row);
} catch (\Exception $e) {
$this->shell->io->err(sprintf('Row %s failed: %s', $row['id'] ?? '?', $e->getMessage()));
return false;
} Prevention
- Validate entities with newEntity()/getErrors() before save.
- Ensure unique constraints (emails, usernames) won't be violated by fixture data.
- Keep schema migrations up to date in seed environments.
- Generate deterministic ids to make re-runs idempotent.
When it happens
Trigger: Seeding test data where a specific row fails to save — schema mismatch, missing required fields, unique-constraint violation (e.g. duplicate username/email), or table not present.
Common situations: Re-running seed commands without cleaning the database (duplicate rows); seeding against an outdated schema; rows referencing non-existent foreign keys (e.g. users removed between runs).
Related errors
- Data for cannot be imported
- Could not save the folder history.
- Could not save the folder relation history.
- Could not save the group, try again later.
- Could not save the UI action, try again later.
AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17).
Data as JSON: /api/errors/b0efd0431b7e8d71.
Report an issue: GitHub.
Appendix: source
Thrown at plugins/PassboltDev/TestData/src/Lib/SaveStrategy/SaveEntity.php:53
*/
public function __construct(DataCommand $shell)
{
$this->shell = $shell;
}
/**
* Save data
*
* @param array $data The data to save
* @return bool
*/
public function save(array $data = []): bool
{
foreach ($data as $row) {
try {
$this->saveEntity($row);
} catch (Exception $e) {
$this->shell->io->err(sprintf('Data "%s" from "%s" could not be inserted', $row['id'], $this->shell->entityName)); //phpcs:ignore
$this->shell->io->err(print_r($row, true));
$this->shell->io->warning($e->getMessage());
return false;
}
}
return true;
}
/**
* Insert an entity.
*
* @param array $data The entity data
* @throws \Exception if the entity can not be validated or saved
* @return void
*/
public function saveEntity(array $data = []): voidView on GitHub (pinned to 31c1bbc10f)