Problem/Motivation

We found that ExistingSite tests (weitzman/drupal-test-traits), were failing with this error:

  Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
  You have requested a non-existent service "database"

Redis 1.11 introduced a hasContainer() guard in CacheBase::deleteMultiple() to allow cache deletes during container rebuild:

$in_transaction = \Drupal::hasContainer() && \Drupal::database()->inTransaction();

On Drupal 11.3, HookCollectorKeyValueWritePass (a new compiler pass) triggers a cache delete during container compilation. At that point hasContainer() returns true (the container builder is set), but the database service definition seems to not yet been registered causing the error.

This breaks ExistingSite tests (weitzman/drupal-test-traits) during setUp() and may affect other scenarios where Redis is active during container compilation.

Steps to reproduce

1. Use drupal/redis 1.11 with Drupal 11.3.3
2. Enable Redis as a cache backend (e.g. REDIS_HOST set in environment)
3. Run ExistingSite tests (weitzman/drupal-test-traits)

Proposed resolution

Add \Drupal::hasService('database') to the guard in CacheBase::deleteMultiple():

$in_transaction = \Drupal::hasContainer() && \Drupal::hasService('database') && \Drupal::database()->inTransaction();

Remaining tasks

Create MR.

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork redis-3575945

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

foxtrotcharlie created an issue. See original summary.

foxtrotcharlie’s picture

Status: Active » Needs review

MR created: https://git.drupalcode.org/project/redis/-/merge_requests/90

This adds \Drupal::hasService('database') to the guard in CacheBase::deleteMultiple(). See issue summary for details.

2.x may be similarly affected in src/Cache/RedisBackend.php (see also #3564915 MR !80). LMK if you'd like a separate MR for 2.x @berdir.

berdir’s picture

Yes please, one for 2.x too

berdir’s picture

Version: 8.x-1.11 » 2.x-dev
Status: Needs review » Fixed

Thanks, merged, still a mystery to me why this would happen during a existing site test, we have those too, but doesn't hurt to be extra careful during a container rebuild.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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