Problem/Motivation

In #838992: Change the uid field from integer to serial by leveraging NO_AUTO_VALUE_ON_ZERO on MySQL we hit an issue because \Drupal\Core\Database\Database static caches database connections across container rebuilds. The postgres schema class static caches schema information which means that an update which affects the table schema will not be reflected in the test runner. The work-around introduced in that issue was to close the db connections after running updates.

This issue will discuss whether we want to fix this in a better way. Normally after rebuilding the container all the services (apart from the one tagged with persist) are new instances. This is not true the database service because it uses \Drupal\Core\Database\Database::getConnection() as a factory.

Steps to reproduce

>>> $database = \Drupal::database();
>>> $cf = \Drupal::configFactory();
>>> drupal_flush_all_caches();
>>> $database === \Drupal::database();
=> true
>>> $cf === \Drupal::configFactory();
=> false

Proposed resolution

Options:

  • Close database connections in \Drupal\Core\DrupalKernel::initializeContainer()
  • Somehow make the database factory a service - this might be very very tricky because the container is load from the database.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Comments

alexpott created an issue. See original summary.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.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.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.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 » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now 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: 10.1.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, which currently accepts only minor-version allowed changes. 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.