Error if migrate destination id contains NULL values

Created on 26 January 2024, 11 months ago
Updated 10 June 2024, 7 months ago

Problem/Motivation

If a destination plugin sets NULL values as part of an id, then we get an error on rollback.

Steps to reproduce

Custom migrate destination plugin with a multiple-value id.
E.g. "a", "b", "c".

Let the destination id contain NULL for some records: E.g. ['A', 'B', NULL].

Create a migration with this destination plugin, with at least one record where the destination id will have a NULL value.
Run the import.

Run the rollback.

We see error messages like this:

Undefined array key "c" Sql.php:597

Technical explanation

The MigrateExecutable::rollback() gets a destination key from $id_map->currentDestination();
It then passes this key to $id_map->deleteDestination(..), which calls ->lookupSourceId() on the Sql id map.

The Drupal\migrate\Plugin\migrate\id_map\Sql::currentDestination() removes NULL values from the destination ids record.
The Drupal\migrate\Plugin\migrate\id_map\Sql::lookupSourceId(..) and also ::deleteDestination(..) expect all values to be present.

Proposed resolution

I see two options:
1. Have Sql::currentDestination() not remove NULL values.
2. Let Sql::lookupSourceId(..) and also Sql::deleteDestination(..) assume NULL if an array key is not present.

In both cases, Sql::lookupSourceId(..) and Sql::deleteDestination(..) need to add an "IS NULL" filter in the query condition.

    foreach ($this->destinationIdFields() as $field_name => $destination_id) {
      if (!isset($destination_id_values[$field_name])) {
        $query->isNull("map.$destination_id");
      }
      else {
        $query->condition("map.$destination_id", $destination_id_values[$field_name], '=');
      }
    }

This

Merge request link

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
MigrationΒ  β†’

Last updated about 13 hours ago

Created by

πŸ‡©πŸ‡ͺGermany donquixote

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024