This error message is generated when trying to use a CSV import, because the "ids" array is duplicated when the plugin is constructed by the core migrate classes. The solution is to apply the patch from #3012001: Duplications within migration process plugin to Drupal core.

Comments

jlscott created an issue. See original summary.

heddn’s picture

Status: Active » Postponed (maintainer needs more info)

Can you provide more steps to reproduce? I haven't been able to make this happen while using the module.

mindaugasd’s picture

Status: Postponed (maintainer needs more info) » Active

Patch fixed the issue as described.
Without this patch most UI links do not work, for example:

  • /admin/structure/migrate/manage/.../migrations/.../source
  • /admin/structure/migrate/manage/.../migrations/.../edit
  • ...and other...

Debugging ksm($this->configuration) in CSV.php line 111 showed all things duplicated, so this error.

heddn’s picture

Ah, so this is for migrations that come from migrate_plus config entities. And we don't have any tests in the project here for that. Should we add some? Probably.

dinarcon’s picture

Hello, I stumbled upon this while writing a blog post on using Migrate Plus to manage migrations from the user interface. The demo module I am using can be found at https://github.com/dinarcon/ud_migrations It is the ud_migrations_config_group_csv_source submodule. Below is a little bit more context of what I found.

It is possible to run import operations from the user interface, but it fails upon rollback throwing the error:

InvalidArgumentException: The ids must a flat array with unique string values. in Drupal\migrate_source_csv\Plugin\migrate\source\CSV->__construct() (line 112 of /var/www/drupalvm/drupal/web/modules/contrib/migrate_source_csv/src/Plugin/migrate/source/CSV.php).

It only fails when the rollback operation is initiated from the user interface. Issuing a Drush command provided by Migrate Tools works fine for reverting the migration. This happens because keys are duplicated as mentioned in the related issue #3012001: Duplications within migration process plugin. One way to mitigate this in Migrate Source CSV is to apply array_unique() on both ends of the condition that checks for the ids configuration.

if (array_unique($this->configuration['ids']) !== array_unique(array_filter($this->configuration['ids'], 'is_string'))) {
  throw new \InvalidArgumentException('The ids must a flat array with unique string values.');
}

I can provide a patch for this, but I am not sure if it is desired. There is already a patch in the related Drupal core's issue that will fix the root of the problem described here.

The problem seems to be related to how import and rollback operations initiated from the user interface are handled by Migrate Tools. For imports, when each batch is called, the $configuration array passed to foreach (NestedArray::mergeDeep($plugin_definition, $configuration) as $key => $value) { is empty so no key duplication occurs and the validation in Migrate Source CSV passes. For rollback operations, the $configuration array has values and the problem arises.

heddn’s picture

I think the real fix is #3012001: Duplications within migration process plugin. But let's leave this open while we wait for it to land upstream.

heddn’s picture

Status: Active » Closed (duplicate)

Upstream has landed. Marking fixed here.