https://www.drupal.org/project/drupal/issues/2959125
Problem/Motivation
It is hard to notice that static_map was the reason a migration row was skipped.
Proposed resolution
Log a message to MigrateSkipRowException to clearly explain why the row is skipped.
The error message has gone through a few iterations, the current #45 is:
No static mapping found for 'Array
(
[0] => bar
[1] => foo
)
' and no default value provided for destination 'destinationproperty'.Remaining tasks
Patch
User interface changes
N.A.
API changes
N.A.
Data model changes
N.A.
| Comment | File | Size | Author |
|---|---|---|---|
| #45 | interdiff-2951715-43-45.txt | 527 bytes | davidsonjames |
| #45 | 2951715-45.patch | 1.78 KB | davidsonjames |
| #43 | interdiff-2951715-37-43.txt | 1.92 KB | davidsonjames |
| #43 | 2951715-43.patch | 1.78 KB | davidsonjames |
| #37 | interdiff_35-37.txt | 2.18 KB | heddn |
Comments
Comment #2
marvil07 commentedComment #3
marvil07 commentedTag
Comment #4
maxocub commentedThis is nice, but it needs tests.
Comment #5
dravenkAdd a test.
Comment #6
dravenkIt is make it fail?
Comment #7
quietone commented@dravenk, thanks for the patch. The new test code should be in a new test method, each method tests one and only thing about the process plugin. I take it from your question "It is make it fail?" that this wasn't tested locally. I could be wrong of course but if you haven't there are instructions in the handbook for Running PHPUnit tests
Comment #8
dravenkThank you for your guidance.
Comment #10
heddnWe've got tests. The IS seems accurate (with a few tweaks now). LGTM.
Comment #11
alexpottCrediting the reviewers for getting tests and the issue summary in order. This is just a task and not a feature.
Comment #12
alexpottI think this exception could be even more helpful and detail which value is not in the map.
The test method should be surrounded by new lines - like all the others.
Comment #13
dravenkThanks for your careful instruction.
Comment #14
alexpott@dravenk thanks for the patch - what about #12.1?
Also... nitpicky...
There needs to be a new line here too. But not doing that introduces a PHPCS. You can see this by running
composer run-script phpcs core/modules/migrate/tests/src/Unit/process/StaticMapTest.phpYou'll see:
Comment #15
dravenkI think exceptions should throw information, otherwise developers might have to spend a lot of time trying to figure out what's wrong with the program.
This command line tool is very useful, thank you. : )
Comment #16
alexpott@dravenk I agree exceptions should be useful. Wouldn't the most useful exception be:
throw new MigrateSkipRowException(sprintf('Skipping, no mapping found for value: %s.', print_r($value, TRUE)));Comment #17
marvil07 commented@dravenk, thanks for adding test coverage!
Last comment now addressed.
Comment #18
heddnCan we include the $destination_property in the exception while we are at it?
Comment #19
rakesh.gectcrTrying to address #18
Comment #20
rakesh.gectcrComment #22
heddnI prefer:
Comment #23
rakesh.gectcrCool, lets roll that out
Comment #25
marvil07 commentedRe-phrasing a bit, and actually updating both test and code.
Comment #26
marvil07 commentedThanks to @rakesh.gectcr for pointing me out on IRC that I used the wrong base patch, so the interdiff on #25 is against #19.
Now a new version based on both #23 and #25.
Comment #27
heddnIf we go with parens for the first case (which I like), then we should probably go w/ parens for the second replacement. Or not use them at all. But using quotes for one and parens for the other seems odd. The reason some grouping is helpful, especially for the value is because of spaces. Which isn't so important for the destination property... since it cannot have spaces. But the default value could be rather long and include spaces.
This comment is wrong. It tests when there is no mapping and no default value.
Comment #28
marvil07 commented#27.1 and #27.2
Comment #29
marvil07 commentedOn the spirit of the intention of this ticket, we may want to add similar changes in other places:
Comment #30
heddnI feel so sad to kick back on such a small thing. If we do sprintf, let's do that for all replacements. Better off just not using sprintf though and putting the values inline in the test.
For the other things you found in #29, let's open those up as individual follow-ups. This is pretty focused already and would derail something that is so close to RTBC. Individual issues will give us the chance to discuss each of these issues on case by case basis.
Comment #31
rakesh.gectcrComment #32
rakesh.gectcrComment #34
jofitz@rakesh.gectcr Let me know if you are working on this and I'll step back, I couldn't find you on IRC to ask.
Comment #35
jofitzConvert $value to a human-readable string.
Comment #36
rakesh.gectcr@jo No problem thatnks for the patch.
I was trying to do individual follow ups according to the comments #30 and #29.
I have added the follow ups for the
MigrateSkipRowException();in following issuesThen I found that we are not able to log the message on
MigrateSkipProcessExceptionSo I have created a follow for that in https://www.drupal.org/project/drupal/issues/2959125
and
Comment #37
heddnI see now why sprintf was used in the tests. Its really hard to make an assertion on:
Here's the closest to the spirit of what I had intended back in #30, given those limitations. This does everything in a sprintf. Consistency.
Comment #38
quietone commentedAdd to meta
Comment #39
heddnI feel this is a pretty novice issue to review. Tagging.
Comment #40
benjifisherComment #41
quietone commentedInstead of parenthesis around the variables in the string it should be single quotes, parenthesis are not used in any other thrown message in the process plugins in migrate. Sometimes double quotes are used but the single quotes appear to be the most common. And let's keep it simple and change 'encountered' to 'found'.
Actually, looking at the existing MigrateSkipRowException messages they do not include the phrase 'skipped because' or similar, they just state the reason, so this could be even simpler. Perhaps, "No static mapping found for 'foo' and no default value provided for destination 'bar'.
Comment #42
rakesh.gectcrComment #43
davidsonjames commentedUpdated patch based on comments in #41.
Comment #44
quietone commentedThis looks great! Just one more thing.
Let's change this to be in accord with the existing summary lines. Change to 'Tests when the source is invalid and there is no default value.' It makes it much easier to see where this test fits in amongst the others.
Comment #45
davidsonjames commentedUpdated the patch based on comments in #44.
I hope this is what you meant.
Comment #46
quietone commentedAssign to review
Comment #47
quietone commentedThanks everyone! This look good and a new error message is always a welcome addition.
This is an example of the new message.
Comment #48
quietone commentedComment #49
alexpottupdating credit.
Comment #50
alexpottCommitted and pushed 522631b064 to 8.6.x and 95dc04ae48 to 8.5.x. Thanks!
The test is unnecessary - we can adjust testMapwithInvalidSource to have the exception message. Also we should use Variable::export() in preference to print_r() - it's output is a bit more condensed and easier to read and has to Drupalisms.