SQL migrations cannot be instantiated if database is not available and Node, Migrate Drupal modules are enabled

Created on 29 September 2022, almost 2 years ago
Updated 12 June 2023, about 1 year ago

Problem/Motivation

We noticed this problem on #3063856-130: Expose full set of debugging data in migrate_message table (filterable/searchable) .

A migration plugin that uses a source derived from SqlBase cannot be instantiated if the configured database connection is disabled. Although the plugin cannot be executed in this case, there are other reasons for instantiating it. For example, it gives access to the map and message tables.

Steps to reproduce

  1. Install Drupal 7 with the devel_generate module (part of the devel project, at least for D7).
  2. Generate some sample content: vocabularies, taxonomy terms, users, menu links, and nodes.
  3. Install Drupal 10, with the patch from #3063856-120: Expose full set of debugging data in migrate_message table (filterable/searchable) , and enable the migrate_drupal_ui module.
  4. Migrate from the D7 site, starting at /upgrade on the D10 site.
  5. Review the migration messages using the pages added in this issue.
  6. Shut down the database server for the D7 site.
  7. Repeat Step 5.

Alternatively,

  1. Install Drupal 10.1.x with the Standard profile.
  2. Define $databases['migrate']['default'] in settings.php with a fake database host or one that is not running.
  3. Enable the migrate_drupal module.
  4. Execute this code: $migration = Drupal::service ('plugin.manager.migration')->createInstance('d7_node_type';. For example, use drush php or add that code to some module.
  5. You should get a message something like this: "PDOException SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo for ddev-drupal7-db failed: Temporary failure in name resolution."

Proposed resolution

Catch the exception.

Drupal\migrate\Plugin\migrate\source\SqlBase::setUpDatabase() already catches ConnectionNotDefinedException and re-throws it as a RequirementsException.

  1. Update SqlBase::checkRequirements() it so that it catches \PDOException and DatabaseException.
  2. Update SqlTestBase as needed because of the changes in (2).
  3. Add test coverage for the exceptions to SqlTestBase.
  4. Add new kernel tests to the migrate and migrate_drupal modules.

Remaining tasks

User interface changes

No more WSOD when using 📌 Add ability to view migrate_message table data Fixed .

API changes

I do not think this counts as an API change.

Data model changes

None

Release notes snippet

N/A

🐛 Bug report
Status

Fixed

Version

10.1

Component
Migration 

Last updated 2 days ago

Created by

🇺🇸United States benjifisher Boston area

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024