Problem / Motivation
The Drupal\migrate\MigrateExecutable class handles imports in such a way that when an exception occurs the only information shared is the log message, which includes brief information that is available from the exception class.
No information about the row being processed is available. Anywhere.
As a result, investigation is required, tracing from the exception and looking at the most recent values in migrate map tables.
Examples
Example 1: preSave Hook
For example, a preSave hook causes a failure:
Error: Call to a member function shouldGenerateTitle() on null in Drupal\commerce_product\Entity\ProductVariation->preSave() (line 332 of /var/www/docroot/modules/contrib/commerce/modules/product/src/Entity/ProductVariation.php) #0 /var/www/docroot/core/lib/Drupal/Core/Entity/EntityStorageBase.php(434)
Yet, it's unclear which row threw the exception.
Example 2:
For example, a MySQL exception occurs:
Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[HY000]: General error: 1366 Incorrect string value: '\xE0 BIRG...' for column 'name' at row 1: INSERT INTO {customer_field_data} (id, vid, langcode, user_id, name, status, created, changed, revision_translation_affected, defau...
There is no log information to understand which row caused this issue.
Proposed Resolution
Allow modules to have access to the exception and the row being processed. One way this could be achieved is to create an event that gets dispatched.
| Comment | File | Size | Author |
|---|---|---|---|
| #14 | interdiff_13-14.txt | 630 bytes | pooja saraah |
| #14 | 2996293-14.patch | 3.91 KB | pooja saraah |
| #13 | core-migrate-exception-event-2996293-13.patch | 3.92 KB | krystalcode |
| #5 | interdiff_2-5.txt | 8.75 KB | qymanab |
| #5 | core-migration-system-exception-event-2996293-5-8.6.x.patch | 5.84 KB | qymanab |
Comments
Comment #2
qymanab commentedComment #3
josephdpurcell commentedOverall this is great! A few minor changes to comments:
Clarify that the row data that had the exception thrown is available to this event.
Clarify this is not just any row, but the row being processed when the exception occurred.
Clarify this is not just any exception, but the exception that was thrown while processing the row.
The row being processed when the exception occurred.
The exception that was thrown during process of the row.
Gets the row that was processed when the exception occurred.
Gets the exception thrown during process of row.
Also, this should have a test. See Drupal\Tests\migrate\Unit\Event\MigratePostRowSaveEventTest and Drupal\Tests\migrate\Unit\Event\MigratePreRowSaveEventTest for examples.
Comment #4
josephdpurcell commentedComment #5
qymanab commentedComment #6
qymanab commentedComment #13
krystalcode commentedUpdated patch for 9.4
Comment #14
pooja saraah commentedFixed failed commands on #13
Attached patch against Drupal 9.4.x