If I mess up my migration's process, then the not very helpful error is something along the lines of:
>Invalid argument supplied for foreach() Migration.php:620 [warning]
This doesn't say:
- which migration is at fault (if the migration being run uses lookups and stubs, then it could be one of the lookup migrations)
- which process item is at fault
This could be fixed by getProcessNormalized doing a sanity check:
if (!is_array($configuration)) {
$migration_id = $this->getPluginId();
throw new \Exception("Invalid process for destination $destination in migration $migration_id.");
}
Manual test results
I added 'test0: 0' to the process pipeline iin the system_logging migration. then ran `drush im syste_logging`.
$ drush mim system_logging
[warning] Invalid argument supplied for foreach() Migration.php:622
[warning] Invalid argument supplied for foreach() Migration.php:622
[warning] Invalid argument supplied for foreach() Migration.php:622
[warning] Invalid argument supplied for foreach() Migration.php:622
[notice] Processed 1 item (0 created, 0 updated, 1 failed, 0 ignored) - done with 'system_logging'
I applied the patch from #16 and now get a useful message.
$ drush ms system_logging
In Migration.php line 391:
Invalid process for destination 'test0' in migration 'system_logging'
Comment | File | Size | Author |
---|---|---|---|
#16 | 2969231-16.patch | 2.86 KB | quietone |
#13 | 2969231-13.patch | 3.57 KB | quietone |
#13 | intertdiff-9-13.txt | 968 bytes | quietone |
#9 | interdiff-7-9.txt | 3.61 KB | quietone |
#9 | 2969231-9.patch | 2.86 KB | quietone |
Comments
Comment #2
quietone CreditAttribution: quietone at Acro Commerce commentedAdd parent
Comment #6
Wim LeersComment #7
quietone CreditAttribution: quietone commentedYes, this would be a nice addition and catch errors early. I have added the code in the IS to Migration.php and added a unit test.
Comment #9
quietone CreditAttribution: quietone commentedSo, there is an existing Kernel test for this, let's just build on that instead of adding a new test.
Comment #11
NickDickinsonWildeLooks good to me - and works beautifully.
I've marked as RTBC, however, I think there is a chance, that
from
/core/modules/migrate/src/Plugin/Migration.php
(line 367 or so) should be removed as unnecessary due to getProcessNormalized() running first. Unless I'm missing some instance that would only run the latter?Comment #13
quietone CreditAttribution: quietone commentedthanks, I meant to come back and mention that and clearly I forgot. I see no reason to not remove that code in this patch.
Comment #14
NickDickinsonWildeLGTM
Comment #15
xjmRegarding #11 / #13.
So, before, we were throwing an exception if
$configurations
wasn't an array right beforeforeach
ing it.getProcessNormalized()
does this:If any configuration child key of
$process
is a string, it converts it to an array. But what if it's a different kind of scalar, or an object? Under those circumstances,getProcessNormalized
would not be guarantee that the child keys of what it returns are also arrays.It's slightly confusing because in
getProcessNormalized()
the return array is called "configurations" (plural) with each child being a configuration (singular). But then in the caller, those individual children are each called "configurations" (plural).This all might be fine, but I'd suggest leaving the earlier exception in for now and addressing a proposal to remove that hunk in a followup.
Comment #16
quietone CreditAttribution: quietone commentedRE-uploading the patch from 9 which does not remove the check from getProcessPlugins().
Follow up made, #3133139: Remove is_array check in getProcessPlugins.
Comment #17
NickDickinsonWildere-rtbc-ing.
Comment #18
quietone CreditAttribution: quietone commentedAdd manual testing to the IS
Comment #19
alexpottCommitted and pushed 93545bd537 to 9.1.x and 145d174fdb to 9.0.x and b1007e34e4 to 8.9.x. Thanks!
This is nice improvement that helps people work out what's going wrong - always a good thing with migrations!
Fixed the test description on commit.