Problem/Motivation
I hit this when running a browser test via the PHPUnit CLI. I had set the SIMPLETEST_DB
environment variable to use a MySQL database that does not exist prior to running the test.
\Drupal\Core\Database\Driver\mysql\Install\Tasks::connect()
removes the database
key from the connection info in order to create the database but fails to re-add it afterwards.
This then leads to an undefined index error in this line in \Drupal\Core\Database\Driver\mysql\Schema::getPrefixInfo()
:
$info['database'] = $this->connection->getConnectionOptions()['database'];
This is called when cleaning up the tables in BrowserTestBase::tearDown()
.
Interestingly the PostgreSQL and SQLite driver already contain to do exactly this.
Proposed resolution
Copy the code over to the MySQL driver to fix the connection info after creating the database.
Comments
Comment #2
tstoecklerHere's a fix.
I tried to write a test for this, but we currently don't have the capability to drop a database which would be required to hit this code path, at least without making any assumptions about the environment. And even if we had such a possibility that would assume that the database user that is used for
SIMPLETEST_DB
has the privilege to drop databases, which is probably not possible. So just the fix.Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedWow, nice! This can be very major issue. We have quite frequent fails with mysql lately.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedWhy not RTBC?
Comment #5
alexpottCommitted and pushed a2d12696bf to 8.6.x and b88bfd25bc to 8.5.x. Thanks!
Yep I think we are seeing this in some random errors on the testbot - for example https://www.drupal.org/pift-ci-job/881923