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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler created an issue. See original summary.

tstoeckler’s picture

Here'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.

Anonymous’s picture

Wow, nice! This can be very major issue. We have quite frequent fails with mysql lately.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Why not RTBC?

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 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

  • alexpott committed a2d1269 on 8.6.x
    Issue #2939026 by tstoeckler: Installer does not fix the database...

  • alexpott committed b88bfd2 on 8.5.x
    Issue #2939026 by tstoeckler: Installer does not fix the database...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.