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
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
Comment #3
foxtrotcharlie commentedMR 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.
Comment #4
berdirYes please, one for 2.x too
Comment #8
berdirThanks, 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.