Problem/Motivation

In #3129043-159: Move core database drivers to modules of their own, @Rajab Natshah reported that on Drupal 9.4, when doing:

drush site:install ... --db-url="mysql://user:password@127.0.0.1/database"

followed by another Drush command, such as:

drush user-create ...

errors would appear like the following:

[error]  TypeError: ############ Argument #1 ($database) must be of type Drupal\Core\Database\Driver\mysql\Connection, Drupal\mysql\Driver\Database\mysql\Connection given

I have not attempted to reproduce this myself, just opening this issue from that report.

I wonder if there's something in Drush or in a contrib module that's type checking for Drupal\Core\Database\Driver\mysql\Connection instead of Drupal\mysql\Driver\Database\mysql\Connection.

Also, would this be fixed if the site:install command were run with ?module=mysql explicitly appended to the db-url?

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

effulgentsia created an issue. See original summary.

effulgentsia’s picture

Issue tags: +9.4.0 update
joseph.olstad’s picture

ya just noticing this upgraded a test environment to 9.4.5, having this very same issue except not drush, it's a custom class I wrote originally back when we were using D9.1 or D9.0.

pwolanin’s picture

We saw this also in our custom code. It's an easy fix, but not BC with older core versions, obviously.

Seems like part of the issue is that the there isn't an interface to type hint? I guess just this abstract class: \Drupal\Core\Database\Connection

loopy1492’s picture

We also had this come up in some custom code. It was using `Drupal\Core\Database\Driver\mysql\Connection` and had to be changed to `Drupal\mysql\Driver\Database\mysql\Connection`.

effulgentsia’s picture

Re #4 and #5, any reason why the custom code needs to type hint to either mysql's Connection class or to an interface? Why not type hint to \Drupal\Core\Database\Connection? Are there circumstances where that's not a suitable type?

loopy1492’s picture

Honestly it's old code and we're just going through break-fixing. Not a whole lot of evaluation trial and error going on.

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.