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.

Comments

josephdpurcell created an issue. See original summary.

qymanab’s picture

josephdpurcell’s picture

Overall this is great! A few minor changes to comments:

  1. +++ b/core/modules/migrate/src/Event/MigrateEvents.php
    @@ -181,4 +181,19 @@
    +   * This event allows modules to perform an action whenever an exception has
    

    Clarify that the row data that had the exception thrown is available to this event.

  2. +++ b/core/modules/migrate/src/Event/MigrateRowSaveExceptionEvent.php
    @@ -0,0 +1,66 @@
    +   * Row object.
    

    Clarify this is not just any row, but the row being processed when the exception occurred.

  3. +++ b/core/modules/migrate/src/Event/MigrateRowSaveExceptionEvent.php
    @@ -0,0 +1,66 @@
    +  protected $exception;
    

    Clarify this is not just any exception, but the exception that was thrown while processing the row.

  4. +++ b/core/modules/migrate/src/Event/MigrateRowSaveExceptionEvent.php
    @@ -0,0 +1,66 @@
    +   *   The row.
    

    The row being processed when the exception occurred.

  5. +++ b/core/modules/migrate/src/Event/MigrateRowSaveExceptionEvent.php
    @@ -0,0 +1,66 @@
    +   *   The exception.
    

    The exception that was thrown during process of the row.

  6. +++ b/core/modules/migrate/src/Event/MigrateRowSaveExceptionEvent.php
    @@ -0,0 +1,66 @@
    +   * Gets the row object.
    

    Gets the row that was processed when the exception occurred.

  7. +++ b/core/modules/migrate/src/Event/MigrateRowSaveExceptionEvent.php
    @@ -0,0 +1,66 @@
    +   * Gets the exception.
    

    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.

josephdpurcell’s picture

Status: Active » Needs work
qymanab’s picture

StatusFileSize
new5.84 KB
new8.75 KB
qymanab’s picture

Version: 8.7.x-dev » 8.6.x-dev
Status: Needs work » Needs review

Status: Needs review » Needs work

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

krystalcode’s picture

Updated patch for 9.4

pooja saraah’s picture

StatusFileSize
new3.91 KB
new630 bytes

Fixed failed commands on #13
Attached patch against Drupal 9.4.x

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.