Problem/Motivation

If you are doing a migration and have an error, then it saves an ID mapping without a destination ID.

When you repeat that row, then the destination receives array(0 => NULL) instead of array(). Personally, I think that's a bad API and I'm not sure what the use case is for supporting that as it leads to bugs like this.

The mentioned method does this:

$old_destination_id_values ? reset($old_destination_id_values) : $this->getEntityId($row);

However, the first part is TRUE, sind the array is not empty, it has a NULL value. That result is that, depending on your migration, it's either silently creating a new entity and ignores the ID you passed in or fails with an error if there is no bundle key in $values.

Seems like a pretty fun way of killing your data, so setting to major.

Proposed resolution

Switch to reset($old_destination_id_values) ?: $this->getEntityId($row), so that it falls back to getting the ID from $row.

Remaining tasks

User interface changes

API changes

Data model changes

Comments

mikeryan’s picture

Status: Needs review » Needs work

Looks good, just needs a test.

alx_benjamin’s picture

Status: Needs work » Needs review
mikeryan’s picture

Status: Needs review » Needs work

Still needs a test.

chx’s picture

Based on the summary, the test should insert a row in the map table direct via $this->container->get('database')->insert() then it should run a migration for which the source id we saved above and then assert the destination id is correct

tduong’s picture

Tried to work on the test but could not make it fail. test_only = interdiff.

berdir’s picture

The following test fails. I had to me two changes. a) set the status to needs update. Apparently that's the only one that's considered in the source. And I had to keep the node.

The reason for that is that my two examples in the issue summary (wrong ID or exception because of missing type) only happen when you do partial migrations without that data (without ID wouldn't work of course, but without type would, if you import additional data into nodes).

In this case however, the way it fails is that it tries to create a new node with the same ID and then explodes on the INSERT query.

We might want to move this to a separate test, maybe also work with a different source than nodes, not sure. Open to suggestions.

chx’s picture

I really like the test except a little detail: the migration re-run should be in a separate method.

Also, since I am changing it anyways, I am testing node 2 instead of node 1. I have a bad feeling about 1: if you were to cast NULL to 0 and add the default auto increment you'd still get to 1. Yes this is vague, not occuring etc. Still, costs us nothing.

I didn't attach an interdiff as it's much bigger than the patch itself.

Edit: I uploaded a test only to #2672416: test only for 2514212 ; ignore .

berdir’s picture

This looks good to me, we need an RTBC from someone who didn't work on the patch I guess.

benjy’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me.

catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 8.1.x and cherry-picked to 8.0.x. Thanks!

  • catch committed 9385c91 on 8.1.x
    Issue #2514212 by Berdir, tduong, chx: Entity::getEntity() does not...

  • catch committed 2b43791 on 8.0.x
    Issue #2514212 by Berdir, tduong, chx: Entity::getEntity() does not...

Status: Fixed » Closed (fixed)

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