Problem/Motivation

This is exactly the same behavior described in this issue
https://www.drupal.org/project/drupal/issues/3507999 related to 10.4x

When launching phpunit tests that uses databases calls, it ends with a TypeError, basically because Drupal try to do some transaction cleanup at the end of the script execution using a database connection that had already been destroyed by phpunit at the end of its test suite.

Steps to reproduce

Just launch phpunit tests

Proposed resolution

I propose to add a test checking the availability of the database connection before launching the unpile task in the Transaction::__destruct() method in order to avoid errors in that particular case.

API changes

Drupal\Core\Database\Connection

Add a method hasClientConnection() to Drupal\Core\Database\Connection in order to have a mean to know if the object is available or not (regardless of this problem it seems wise to me to have this method)

test of the client's connection avaibility

Implement a test of the connection avaibility using this method either in
Drupal\Core\Database\Transaction::__destruct() method to avoid launching unpile
or more deeper in Drupal\Core\Cache\DatabaseCacheTagsChecksum::doInvalidateTags (which is the where the problem really occurs).

Issue fork drupal-3538834

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

ceonizm created an issue. See original summary.

ceonizm’s picture

ceonizm’s picture

@mondrake
I've cloned #3406985, copied my module into and tested to launch phpunit on my kernel tests and I can confirm you I also don't get the error with it.

ceonizm’s picture

Status: Active » Needs review
smustgrave’s picture

Version: 11.2.x-dev » 11.x-dev
Status: Needs review » Needs work

Thanks for working on this. MR should point to 11.x as the current development branch

ceonizm’s picture

Status: Needs work » Needs review
Issue tags: +PHPUnit
smustgrave’s picture

Status: Needs review » Needs work

#7 still stands. And just going off the title our pipelines would be failing right?

mondrake’s picture

If #3406985: Convert all transactions in core to use explicit ::commitOrRelease() fixes the issue, I would not pursue this. Under normal circumstances, there should not be the need to check that the client connection is active.

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.