Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293780

[regression] With Drupal 9.4, can no longer call Database::getConnection() from within settings.php due to driver classes not yet in autoloader

$
0
0

Problem/Motivation

In Drupal 9.3, it was possible to do the following within settings.php:

$databases['default']['default'] = [
...
];
Database::setMultipleConnectionInfo($databases);
try {
  Database::getConnection();
}
catch (Exception $e) {
  // Do something
}

In Drupal 9.4, this now fails because the database driver is in core/modules/$driver, and that's not in the autoloader until after settings.php completes.

This can be worked around by adding $class_loader->addPsr4('Drupal\\mysql\\', 'core/modules/mysql/src/') prior to calling Database::getConnection();, but for sites with settings.php files that don't do that yet, this is a regression.

Acquia Cloud is one example where code like the above in settings.php (or rather, a .inc file included by settings.php) is done. I don't know if other Drupal hosting platforms employ similar constructs.

Steps to reproduce

Proposed resolution

Given that a workaround is possible, I don't know if we want to address this issue in core. If we do, then perhaps something like moving the current Settings::initialize() code for setting up the autoloader into Database::getConnection() might solve it? Maybe other ideas?

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 293780

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>