When getIdMap() is called from the MigrateExecutable MigrateIdMapInterface::setMessage($message) is called. However when a migration is created through the migration process plugin, the setMessage method is not called.

This means that if there are any messages, instead of recording them it will cause a fatal error due to calling display() on null.

The documentation for setMessage() was also flat out wrong - suggesting that the param should be a message string instead of a MigrateMessageInterface; also a couple of other minor docstring fixes.

Comments

NickWilde created an issue. See original summary.

nickdickinsonwilde’s picture

Version: 8.3.x-dev » 8.2.x-dev
Status: Needs work » Needs review
StatusFileSize
new3.08 KB

actually I *think* this bugfix is okay for 8.2.x

nickdickinsonwilde’s picture

should be noted that in *most* cases there aren't messages to save, but I managed to trigger it by doing something ahem different.

Status: Needs review » Needs work

The last submitted patch, 2: 2864563-migration-process-plugin-2.patch, failed testing.

mikeryan’s picture

Version: 8.2.x-dev » 8.3.x-dev
Issue tags: +Needs reroll

Good catch, I saw this happen recently and didn't have a chance to track it down.

At this points bug fixes should go against 8.3.x - I don't believe there will be any more 8.2.x releases, barring critical security fixes (which won't include "normal" bug fixes).

nickdickinsonwilde’s picture

StatusFileSize
new3.35 KB

Ah okay, thought there was one or two more.
Here it is rolled for 8.3.x (and including the use statement I neglected to include ahem).

nickdickinsonwilde’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll

Status: Needs review » Needs work

The last submitted patch, 6: 2864563-migration-process-plugin-6.patch, failed testing.

nickdickinsonwilde’s picture

Assigned: Unassigned » nickdickinsonwilde

ah need to mock another method...

nickdickinsonwilde’s picture

Assigned: nickdickinsonwilde » Unassigned
Status: Needs work » Needs review
StatusFileSize
new4.22 KB

Status: Needs review » Needs work

The last submitted patch, 10: 2864563-migration-process-plugin-9.patch, failed testing.

nickdickinsonwilde’s picture

Status: Needs work » Needs review

never seen that error... looks like a testbot fail, requeueing

Status: Needs review » Needs work

The last submitted patch, 10: 2864563-migration-process-plugin-9.patch, failed testing.

nickdickinsonwilde’s picture

Status: Needs work » Needs review

Er that test passed you silly bot!

heddn’s picture

Assigned: Unassigned » heddn

Assigning to myself to do a review this week.

heddn’s picture

Version: 8.3.x-dev » 8.4.x-dev
Assigned: heddn » Unassigned
Status: Needs review » Needs work
Issue tags: +Needs reroll

This needs a re-roll after #2845486: Rename Migration process plugin and add documentation. Can we also see a tests only patch to demonstrate the problem?

gaurav.kapoor’s picture

Status: Needs work » Needs review
StatusFileSize
new3.29 KB

Re roll.

Status: Needs review » Needs work

The last submitted patch, 17: 2864563-17.patch, failed testing.

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new2.71 KB
new5.03 KB

Correct the omissions in the re-roll.

jofitz’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Re-setting to Needs Work for adding a tests-only patch to demonstrate the problem (as requested by @heddn in #16).

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new2.61 KB
new7.32 KB

Added a test to make sure setMessage() is called.

The last submitted patch, 21: 2864563-21-test_only.patch, failed testing.

heddn’s picture

Assigned: Unassigned » heddn

Assigning to myself to review this week.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

I'm comfortable calling this one done. The test looks pretty heafty, not sure if that could be refactored but it does the job. @heddn, feel free to jump in.

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
+++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
@@ -222,15 +223,17 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+      $id_map->setMessage(new MigrateMessage());

This is tying understanding of how the id map works in the migration lookup class.

Are we sure we want to do that?

Shouldn't the id map do this itself? It would make sense for it to have knowledge of how to create a new MigrateMessage class if it needs one.

It doesn't make sense for this knowledge to be embedded in the MigrationLookup class. It also means anyone else using that needs to know that knowledge too.

This is known as 'Inappropriate intimacy'.

heddn’s picture

Title: Migration process plugin doesn't call setMessage on the migration idMap » Migration lookup process plugin doesn't call setMessage on the migration idMap
Status: Needs review » Needs work
+++ b/core/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
@@ -222,15 +223,17 @@ public function transform($value, MigrateExecutableInterface $migrate_executable
+        $id_map->saveMessage($stub_row->getSourceIdValues(), $e->getMessage());

Perhaps saveMessage could new it up or inject it somehow if the object doesn't yet exist. I think doing that would address the problem in the IS. If we do that, do we want to deprecate setMessage then? I haven't looked at the code closely enough to make a call on that.

heddn’s picture

Assigned: heddn » Unassigned
larowlan’s picture

Status: Needs work » Needs review
StatusFileSize
new2.56 KB
new7.81 KB

this is what I was trying to articulate earlier

heddn’s picture

  1. +++ b/core/modules/migrate/src/Plugin/MigrateIdMapInterface.php
    @@ -268,10 +268,10 @@ public function destroy();
       public function setMessage(MigrateMessageInterface $message);
    

    Should we mark setMessage as deprecated then too?

  2. +++ b/core/modules/migrate/src/Plugin/migrate/id_map/Sql.php
    @@ -156,6 +157,7 @@ public function __construct(array $configuration, $plugin_id, $plugin_definition
    +    $this->message = new MigrateMessage();
    

    This looks great.

  3. +++ b/core/modules/migrate/tests/src/Unit/process/MigrationLookupTest.php
    @@ -62,6 +62,7 @@ public function testTransformWithStubbing() {
    +    $destination_id_map->setMessage(Argument::any())->willReturn(NULL);
    
    +++ b/core/modules/migrate/tests/src/Unit/process/MigrationTest.php
    @@ -108,6 +108,7 @@ public function testTransformWithStubbing() {
    +    $id_map->setMessage(Argument::any())->willReturn(NULL);
    

    Is this necessary any more? Or is that a follow-up?

larowlan’s picture

Issue tags: +Novice

There is one other call to setMessage so I think keep it, removing it is out of scope here.

w.r.t test changes - yep they can go.

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

jofitz’s picture

Issue tags: -Novice
StatusFileSize
new1.61 KB
new6.53 KB

Having waited 21 days for a Novice, I've gone ahead and made the minor changes recommended by @heddn and @larowlan in #29/#30.

This is probably ready for RTBC, but I can't do that having contributed a few patches to this issue.

joelpittet’s picture

Version: 8.5.x-dev » 8.4.x-dev
Status: Needs review » Reviewed & tested by the community

Back to RTBC as items have been addressed from #29 and #30

catch’s picture

Status: Reviewed & tested by the community » Fixed

Fixed this on commit to 8.5.x/cherry-pick to 8.4.x, thanks!

FILE: ...e/modules/migrate/src/Plugin/migrate/process/MigrationLookup.php
----------------------------------------------------------------------
FOUND 0 ERRORS AND 1 WARNING AFFECTING 1 LINE
----------------------------------------------------------------------
 6 | WARNING | [x] Unused use statement
----------------------------------------------------------------------
PHPCBF CAN FIX THE 1 MARKED SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

  • catch committed 9cf72c6 on 8.5.x
    Issue #2864563 by Jo Fitzgerald, NickWilde, larowlan, gaurav.kapoor,...

  • catch committed 4c904b7 on 8.4.x
    Issue #2864563 by Jo Fitzgerald, NickWilde, larowlan, gaurav.kapoor,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.