Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#14 | 2880278-14.patch | 1.39 KB | ezeedub |
Comments
Comment #2
Fonski CreditAttribution: Fonski commentedHere is a simple patch that skip null values.
Comment #4
quietone CreditAttribution: quietone as a volunteer commentedThe iterator plugin is now the SubProcess plugin.
Comment #5
quietone CreditAttribution: quietone as a volunteer commentedReplaced deprecated name with current name in the title
Comment #6
jofitz CreditAttribution: jofitz at ComputerMinds commentedYou 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.
Comment #7
jofitz CreditAttribution: jofitz at ComputerMinds commentedAdded a test. No interdiff because the only change is in the test_only patch.
Comment #9
heddnIs 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.
Comment #10
jofitz CreditAttribution: jofitz at ComputerMinds commented@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 withcontinue
within the new conditional. An alternative would be to surround$return[$key] = $destination;
withif (!is_null($key))
. Any preference? Or is this issue irrelevant and not worth any more of my time.Comment #11
phenaproximaI 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.
Comment #14
ezeedub CreditAttribution: ezeedub commentedRe-roll for 8.7
Comment #15
mikelutzThe 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.
Comment #16
mikelutzComment #17
heddnLet's add a skip row exception instead of just continuing.
Comment #20
mikelutzClosing 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.