fallback on 'migrate' as the database key causes error messages if migrations use a different source

Created on 28 June 2021, over 3 years ago
Updated 5 December 2024, about 2 months ago

Problem/Motivation

I am creating migrations that use the local Drupal 8 site as the source (to convert image fields and other entities to media entities).

Accordingly, my migration's source is configured like this:

  source:
    # Use the site's own DB as the source.
    key: default
    target: default

However, when I run a migration command such as 'drush ms MYMIGRATION', I see this warning:

 [error]  Message: Failed to connect to your database server. The server reports the following
message: /No database connection configured for source plugin variable/.
 * Is the database server running?
 * Does the database exist, and have you entered the correct database name?
 * Have you entered the correct username and password?
 * Have you entered the correct database hostname?

This is caused by a combination of migrate's SqlBase source doing this:

  protected function setUpDatabase(array $database_info) {
    if (isset($database_info['key'])) {
      $key = $database_info['key'];
    }
    else {
      // If there is no explicit database configuration at all, fall back to a
      // connection named 'migrate'.
      $key = 'migrate';
    }

and a migration probably in migrate_drupal using the Drupal\migrate_drupal\Plugin\migrate\source\Variable plugin.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Active

Version

11.0 🔥

Component

migration system

Created by

🇬🇧United Kingdom joachim

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

Merge Requests

Comments & Activities

Not all content is available!

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

  • 🇬🇧United Kingdom richardhobbs

    I get the above error message when I do a drush cr followed by drush ms if I do drush ms again there is no error message until I do another drush cr

    Drupal 10.3.10

    Migrate Plus 6.0.5
    Migrate Tools 6.0.5

  • 🇧🇬Bulgaria pfrenssen Sofia

    The error is originating from migrate_drupal_migration_plugins_alter() but should not be emitted. The code is doing a requirements check for migrating the "variables" subsystem, but this doesn't exist in Drupal 8+ since variables were replaced with config.

    There is similar code just above that will suppress the exception for sites running Drupal 7+ which do not meet the requirements of the D6 taxonomy vocabulary migration:

        catch (RequirementsException $e) {
          // This code currently runs whenever the definitions are being loaded and
          // if you have a Drupal 7 source site then the requirements will not be
          // met for the d6_taxonomy_vocabulary migration.
        }
    

    We can follow the same pattern, something like this:

        catch (RequirementsException $e) {
          // This code currently runs whenever the definitions are being loaded and
          // if you have a Drupal 8+ source site then the requirements will not be
          // met for the system_site migration since the 'variables' subsystem was
          // replaced with config entities in Drupal 8.
        }
    
  • Pipeline finished with Failed
    4 days ago
    Total: 137s
    #399459
  • 🇧🇬Bulgaria pfrenssen Sofia
  • Pipeline finished with Failed
    4 days ago
    Total: 462s
    #399465
  • Pipeline finished with Failed
    4 days ago
    Total: 505s
    #399467
Production build 0.71.5 2024