Problem/Motivation
In #2752961 a new method for clearing Twig cache was introduced and committed to 8.6.x branch.
Such method relies on calling \Drupal::service('twig')->invalidate(); in two key places:
In drupal_flush_all_caches():
function drupal_flush_all_caches() {
...
// Invalidate the container.
\Drupal::service('kernel')->invalidateContainer();
// Wipe the Twig PHP Storage cache.
\Drupal::service('twig')->invalidate();
...
And in drupal_rebuild():
function drupal_rebuild($class_loader, Request $request) {
...
// Force kernel to rebuild php cache.
\Drupal::service('twig')->invalidate();
...
// Invalidate the container.
$kernel->invalidateContainer();
As you can see above the second time the "twig" service is called before the container invalidation and this creates the following issue when running Drush (~9) cache rebuild, as the container is not yet available:
$ ./vendor/bin/drush cr
[error] \Drupal::$container is not initialized yet. \Drupal::setContainer() must be called with a real container.
This is possibly due to how Drupal is bootstrapped in \Drush\Commands\core\CacheCommands::rebuild(), nevertheless I believe that this is a core issue, given the inconsistent situation outlined above.
Proposed resolution
In "drupal_rebuild()" move "twig" service invocation after container invalidation.
Remaining tasks
Provide patch.
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2969652-fix-twig-cache-invalidation.patch | 861 bytes | ademarco |
Comments
Comment #2
ademarco commentedComment #3
ademarco commentedClosing as outdated as, in the meanwhile, this has been fixed by @alexpott in #2752961