passbolt/passbolt_api · error

Data for cannot be imported

Error message

Data for %s cannot be imported

What it means

DataCommand is the base class for passbolt test-data seed commands (in the TestData dev plugin). Its execute() wraps the whole data import in a try/catch; when any Exception escapes the import it prints a generic per-entity message 'Data for <entity> cannot be imported' plus the exception text as a warning, and returns CODE_ERROR. This is a top-level catch-all for seeding failures.

Solutions

  1. Check the warning line printed below the error for the real exception message.
  2. Run pending migrations: `ddev refresh` or `bin/cake migrations migrate`.
  3. Verify database connectivity and credentials in config/app.php.
  4. Re-run with a smaller count to isolate the offending row.
  5. Fix duplicates/conflicting data (e.g. existing users with the same username) then retry.

Example fix

// before
} catch (Exception $e) {
    $io->err(sprintf('Data for %s cannot be imported', $this->entityName));
// after
} catch (Exception $e) {
    $io->err(sprintf('Data for %s cannot be imported: %s', $this->entityName, $e->getMessage()));
Defensive patterns

Strategy: try-catch

Validate before calling

// before seeding
$connection = \Cake\Datasource\ConnectionManager::get('default');
$connection->execute('SELECT 1'); // connectivity check
$status = (new \Migrations\MigrationManager($connection))->status ?? null; // ensure migrations applied via bin/cake migrations status

Try / catch

try {
    $command->run($args, $io);
} catch (\Exception $e) {
    $io->error('Seeding failed: ' . $e->getMessage());
    // inspect $e->getPrevious() for the root DB error
}

Prevention

When it happens

Trigger: Running a test-data seeding command (e.g. `passbolt testdata users|groups|resources ...`) when the entity-specific insert logic throws — database insert failures, missing tables/migrations, validation exceptions bubbling from save strategies.

Common situations: Seeding test data into an environment whose schema is out of date (migrations not run); database connection problems; seeding entities that violate constraints (duplicate emails/usernames).

Related errors


AI-assisted analysis of passbolt/passbolt_api@31c1bbc10f (2026-09-17). Data as JSON: /api/errors/a47ac33f7ef2ab6c. Report an issue: GitHub.

Appendix: source

Thrown at plugins/PassboltDev/TestData/src/Lib/DataCommand.php:97

        // Console IO used by the Save Strategies
        $this->io = $io;

        // $conn = \Cake\Datasource\ConnectionManager::get('default');
        // $conn->logQueries(true);

        // Insert the data in the db.
        $data = $this->getData();
        try {
            $this->save($data);
            // old fashion way (can be useful for debugging)
            // return $this->saveOneByOne();
            $endTime = time();
            $dtF = new DateTime("@$startTime");
            $dtT = new DateTime("@$endTime");
            $diff = $dtF->diff($dtT)->format('%im %ss');
            $io->out('Data for entity "' . $this->entityName . '" inserted (' . count($data) . ') in ' . $diff);
        } catch (Exception $e) {
            $io->err(sprintf('Data for %s cannot be imported', $this->entityName));
            $io->warning($e->getMessage());

            return static::CODE_ERROR;
        }

        return static::CODE_SUCCESS;
    }

    /**
     * Display the progress bar
     *
     * @param int $total Number total of tasks
     * @return \Cake\Console\Helper\ProgressHelper|null
     */
    public function displayProgressBar(int $total): ?ProgressHelper
    {
        $progress = null;

View on GitHub (pinned to 31c1bbc10f)