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
Comment #2
effulgentsia commentedComment #3
joseph.olstadya 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.
Comment #4
pwolanin commentedWe 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
Comment #5
loopy1492 commentedWe 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`.
Comment #6
effulgentsia commentedRe #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?Comment #7
loopy1492 commentedHonestly it's old code and we're just going through break-fixing. Not a whole lot of evaluation trial and error going on.