{"record":{"id":"b0efd0431b7e8d71","repo":"passbolt/passbolt_api","slug":"data-s-from-s-could-not-be-inserted","errorCode":null,"errorMessage":"Data \"%s\" from \"%s\" could not be inserted","messagePattern":"Data \"(.+?)\" from \"(.+?)\" could not be inserted","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"plugins/PassboltDev/TestData/src/Lib/SaveStrategy/SaveEntity.php","lineNumber":53,"sourceCode":"     */\n    public function __construct(DataCommand $shell)\n    {\n        $this->shell = $shell;\n    }\n\n    /**\n     * Save data\n     *\n     * @param array $data The data to save\n     * @return bool\n     */\n    public function save(array $data = []): bool\n    {\n        foreach ($data as $row) {\n            try {\n                $this->saveEntity($row);\n            } catch (Exception $e) {\n                $this->shell->io->err(sprintf('Data \"%s\" from \"%s\" could not be inserted', $row['id'], $this->shell->entityName)); //phpcs:ignore\n                $this->shell->io->err(print_r($row, true));\n                $this->shell->io->warning($e->getMessage());\n\n                return false;\n            }\n        }\n\n        return true;\n    }\n\n    /**\n     * Insert an entity.\n     *\n     * @param array $data The entity data\n     * @throws \\Exception if the entity can not be validated or saved\n     * @return void\n     */\n    public function saveEntity(array $data = []): void","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/passbolt/passbolt_api/blob/31c1bbc10f32808a607fa9bd81891e898779c0bc/plugins/PassboltDev/TestData/src/Lib/SaveStrategy/SaveEntity.php#L35-L71","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":"// before\n$this->shell->io->err(sprintf('Data \"%s\" from \"%s\" could not be inserted', $row['id'], $this->shell->entityName)); //phpcs:ignore\n// after\n$this->shell->io->err(sprintf('Data \"%s\" from \"%s\" could not be inserted: %s', $row['id'], $this->shell->entityName, $e->getMessage())); //phpcs:ignore","handlingStrategy":"validation","validationCode":"// before saving a row\n$errors = $table->newEntity($row)->getErrors();\nif ($errors) {\n    var_dump($errors); // fix row before insert\n    return false;\n}","typeGuard":"function isSaveableRow(array $row): bool {\n    return isset($row['id']) && is_string($row['id']) && $row['id'] !== '';\n}","tryCatchPattern":"try {\n    $this->saveEntity($row);\n} catch (\\Exception $e) {\n    $this->shell->io->err(sprintf('Row %s failed: %s', $row['id'] ?? '?', $e->getMessage()));\n    return false;\n}","preventionTips":["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."],"tags":["test-data","seeding","save-failure","database"],"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"}