Problem/Motivation

When Drupal cannot connect to the migration database, migrate_drupal_migration_plugins_alter() adds an error to the messenger service:

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?

There are two problems:

  1. The problem usually has nothing to do with the variable source plugin.
  2. Adding the error to the messenger service means that it is unpredictable where this error will be displayed.

The same error message is generated by the credential form in migrate_drupal_ui. The first problem applies there, but not the second.

Steps to reproduce

WIth Drush:

  1. Install Drupal with the Standard profile.
  2. Enable the migrate_drupal module.
  3. Clear caches: drush cr.
  4. Check migration status: drush ms. You will see the error message.

WIth #3063856: Add ability to view migrate_message table data:

  1. Install Drupal with the Standard profile.
  2. Enable the migrate_drupal module.
  3. Add test_log.yml to the migrations/ directory of any enabled module.
  4. Execute the test_log migration. It should create one migration message.
  5. Clear caches and visit /admin/reports/migration-messages. You should see the error message.

Proposed resolution

For (1), move the error message reported by the server after the list of suggested remedies.

For (2), find a more reliable way to track errors.

Remaining tasks

User interface changes

Different error messages.

API changes

None

Data model changes

None

Release notes snippet

N/A

Comments

benjifisher created an issue. See original summary.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.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.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

kiseleva.t’s picture

Status: Active » Needs review
StatusFileSize
new1.5 KB

For (2), find a more reliable way to track errors.

Replaced adding error to Drupal messages by Drupal logger to have that error in logs, also added name of migration to message to make it clear.

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

Status: Needs review » Needs work
robpowell’s picture

StatusFileSize
new176.48 KB

This worked on 9.3.14, going to rerun tests to see if those failures were a fluke.
drush watchdog log

robpowell’s picture

Status: Needs work » Needs review
mikelutz’s picture

Status: Needs review » Needs work

Looks like this needs more work and tests either way.

mikelutz’s picture

Test fails seem to be real too, though I'm not sure why this change is causing those particular fails.

quietone’s picture

Status: Needs work » Needs review
StatusFileSize
new2.02 KB

Did some debugging and it is failing because the watchdog table does not exist.

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'test.test61444075watchdog' doesn't exist

But why did we not get a more useful error message? All I can say it that it gets into what appears to be an infinite loop at this line in the mysql ExceptionHandler.

No interdiff, I only 1 line to MigrationPluginListTest.php

liam morland’s picture

I was able to silence the error No database connection configured for source plugin variable. by adding this to settings.php:

$databases['migrate']['default'] = $databases['MY_SOURCE_DATABASE_KEY']['default'];

Even without this, Drupal can see the migration data. So, some part of Drupal must be defaulting to the migrate key even when that is not what is configured to be used.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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.

danflanagan8’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

It looks like the latest patch makes both of the changes on the "Proposed Resolution". But per @mikelutz in #9 this still needs tests. Tagging and setting back to NW.

benjifisher’s picture

Issue summary: View changes
StatusFileSize
new253 bytes

Part of the difficulty with this issue is that we do not have good steps to reproduce the problem. We need that before we can write a test.

It is easy with Drush: just enable the migrate_drupal module and drush cr and drush ms. But we need a way to reproduce the problem with just Drupal core.

I previously suggested (in the issue description) using the patch from #3063856: Add ability to view migrate_message table data. In order for that to work, you need to run some migration that creates messages. You could do a full migration from D6 or D7. A more minimal approach is to add the attached migration to mymodule/migrations/, where mymodule is any enabled module. Then execute the migration: it will add one message. I am updating the issue summary to suggest this.

Unless someone can think of a better way to test, we may as well postpone this issue on #3063856.

I also tested the current patch from #3312733: SQL migrations cannot be instantiated if database is not available and Node, Migrate Drupal modules are enabled. It did not make any difference.

Version: 10.1.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, which currently accepts only minor-version allowed changes. 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.