I have a bit complex migrate configuration.
In the SubProcess plugin, if one of the value is null, an error occurs (because there is a null value passed to the Row constructor).

We can just ensure that, in the sub_process, the value is not null.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Fonski created an issue. See original summary.

Fonski’s picture

Here is a simple patch that skip null values.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

quietone’s picture

Status: Active » Needs work
Issue tags: +Needs reroll

The iterator plugin is now the SubProcess plugin.

quietone’s picture

Title: Ensure each value is not null in migrate Iterator process. » Ensure each value is not null in SubProcess process plugin

Replaced deprecated name with current name in the title

jofitz’s picture

Assigned: Fonski » jofitz
Status: Needs work » Needs review
Issue tags: -Needs reroll +Needs tests
FileSize
793 bytes

You know I can't resist a reroll!

This will also need test(s) which I will look at now, but let's push this past the testbot first.

jofitz’s picture

Added a test. No interdiff because the only change is in the test_only patch.

The last submitted patch, 7: 2880278-7-test_only.patch, failed testing. View results

heddn’s picture

Issue summary: View changes
Status: Needs review » Needs work

Is this the right thing though? It looks like Row accepts an empty array, so maybe a better fix is to check for non-array and cast to array? I'm not sure. But GIGO is maybe a valid option here.

jofitz’s picture

Status: Needs work » Needs review
FileSize
648 bytes
1.32 KB

@heddn If non-array values are converted to an empty array then the code can continue, but returns an additional array entry: [NULL => NULL] which is undesired, so I have stuck with continue within the new conditional. An alternative would be to surround $return[$key] = $destination; with if (!is_null($key)). Any preference? Or is this issue irrelevant and not worth any more of my time.

phenaproxima’s picture

Status: Needs review » Needs work

I like the idea here, but I don't think we should silently continue the loop if the value is not an array. At the very least, we should log a message in the migration's message table, or skip the processing (MigrateSkipProcessException) -- something more verbose than a silent skip.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

ezeedub’s picture

Version: 8.6.x-dev » 8.7.x-dev
FileSize
1.39 KB

Re-roll for 8.7

mikelutz’s picture

Title: Ensure each value is not null in SubProcess process plugin » SubProcess should throw an explicit error on bad input.

The documentation for sub_proces specifically says that it's expected input is an array of associative arrays. If there is a non-array value in the outer array, then there is a problem with the calling code that needs to be addressed. We should not simply skip past elements that do not meet this criteria. If we do anything here, we should throw a skip process or skip row exception with a message indicating the invalid input.

Anyone executing a custom migration that requires gracefully ignoring null rows should implement their own sub_process plugin that handles it, we shouldn't quietly ignore bad inputs in core.

mikelutz’s picture

heddn’s picture

Let's add a skip row exception instead of just continuing.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

mikelutz’s picture

Status: Needs work » Closed (duplicate)

Closing this as a duplicate of #3048464: SubProcess migrate process plugin should throw exception on invalid input. This issue is older, but that issue is further along and more comprehensive.