Problem/Motivation
Rolling back a migration that had failed items doesn't actually revert the failed migrated items. I tried migrating a CSV into a node type with a missing title. Obviously this failed. But then rollback also failed to roll-back the failed items.
Truncating the migrate_map_foo table resolves things as a manual work around.

Proposed resolution
Looks like currentDestination() returns array(NULL) in that case. This needs to change.
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | migrate-rollback_failed_items-2579343-19.patch | 4.87 KB | lendude |
| #19 | interdiff-2579343-17-19.txt | 1.04 KB | lendude |
| #17 | migrate-rollback_failed_items-2579343-17.patch | 4.54 KB | lendude |
| #17 | interdiff-2579343-12-17.txt | 1.11 KB | lendude |
| #12 | migrate-rollback_failed_items-2579343-12.patch | 3.29 KB | lendude |
Comments
Comment #2
heddnComment #3
mikeryanNote: looks to me like the fault is in currentDestination(), returning array(NULL) for failed rows, which results in the attempt to delete entities with an id of NULL.
Comment #4
drclaw commentedHere's a patch to get the ball rolling on this one. I'm not 100% sure if this is the right approach but I figured I'd take a stab at it. Mostly I'm worried about:
\Drupal\migrate\Plugin\MigrateIdMapInterfacewill break any existing contrib implementations (may not be an issue while still in rc2...?) - this could be avoided if there is an existing way to get the current row source values; I just couldn't find one.currentDestination()to return NULL if all the destination keys are NULL (instead an array ofdestination_key => NULLlike it was before) which might be an issue for any code using it and expecting an array. Although, the method doc does indicate that NULL is a possible return value...Anyway, I didn't write any tests yet. I thought I'd get some feedback on the approach first.
Thanks!
Comment #5
mikeryanYes, I think that's the right approach - only logical to have a currentSource() call.
Rather than separate delete calls, it would be simlper to just delete by the source key in all cases.
Comment #7
mikeryanLet's see how the last patch does with 8.2.x...
Comment #8
mikeryanActually, bug fixes should go against 8.1.x.
Comment #9
mikeryanWe still need tests here.
Comment #10
mikeryanHow was this never set to major?
Comment #11
lendudeRan into this, applied patch, "Rolled back 651 items - done", nice!
Bit of nitpicking while I'm here:
This should be turned into an actual english sentence.
This addition makes this an API change and so this should go to 8.2.x, or doesn't that count in experimental modules?
Comment #12
lendudeAdded a test and fixed nitpick. Leaving it at 8.1.x for now.
Comment #14
mikeryanLooks good to me!
I think this is OK for 8.1.x - the only BC break would be if someone out there were implementing their own id_map, which is an unlikely scenario.
Comment #15
alexpottI really like this patch it adds a much needed method. However, this is the only test coverage added. It would be awesome to get test coverage of the new currentSource() method and the changes to currentDestination(). I would have expected additional coverage in \Drupal\Tests\migrate\Unit\MigrateSqlIdMapTest
Comment #16
alexpottAlso for me this is a migrate critical - failing to rollback failed items will break migrations and the work around of truncating the table is not good.
Comment #17
lendudeAdded test coverage for currentSource() and currentDestination(). Grouped the coverage together in one test method since they are basically returning two sides of the same data set. But if we want one test method per class method I can see the benefit in that too, *shrug*.
Also, I didn't find a better way to start it up then by calling
$id_map->rewind();, which feels weird, but starting with next() gave a fatal. So if there is a better way to initialise all the needed variables, let me know.Comment #18
mikeryanMuch as I hate to set it back - the change in currentDestination() affects the case when a destid column is NULL, so that case needs to be tested.
Comment #19
lendude@mikeryan, no worries, more test coverage is always good.
Were you thinking about something like this?
Comment #20
mikeryanAlrighty, thanks!
Comment #21
alexpottCommitted and pushed 51a76ef to 8.3.x and 2960609 to 8.2.x and 4408487 to 8.1.x. Thanks!
As a migrate critical this can go against all three branches because migrate is not yet out of alpha.