Problem/Motivation
I am porting a module to D8 (Field as Block) which makes use of a post render cache callback. When I uninstall the module I get a white screen with a not-very-helpful error message:
Error
The website has encountered an error. Please try again later.
To reproduce this error:
- do a standard install
- install the fieldblock module (I assume any module implementing a post render cache callback can trigger this problem)
- create an article node
- set up a fieldblock using the Manage Display and Block Layout screens
- warm the render cache by visiting /node/1
- disable fieldblock (drush pmu fieldblock)
- refresh /node/1
The Drupal log (drush ws --extended) shows the following messages:
ID Date Type Severity Message
35 19/Oct 00:08 php Recoverable fatal error: Argument 1 passed to Drupal\Core\Cache\Cache::validateTags() must
be of the type array, null given, called in
/var/www/drupal8/core/lib/Drupal/Core/Cache/Cache.php on line 45 and
defined in Drupal\Core\Cache\Cache::validateTags() (line 63 of
/var/www/drupal8/core/lib/Drupal/Core/Cache/Cache.php).
34 19/Oct 00:08 php Warning: Invalid argument supplied for foreach() in
_drupal_render_process_post_render_cache() (line 3241 of
/var/www/drupal8/core/includes/common.inc).
33 19/Oct 00:08 php Warning: Invalid argument supplied for foreach() in
_drupal_render_process_post_render_cache() (line 3241 of
/var/www/drupal8/core/includes/common.inc).
32 19/Oct 00:08 php Warning: call_user_func_array() expects parameter 1 to be a valid callback, class
'Drupal\fieldblock\Plugin\Block\FieldBlock' not found in
_drupal_render_process_post_render_cache() (line 3242 of
/var/www/drupal8/core/includes/common.inc).
31 19/Oct 00:08 php Warning: call_user_func_array() expects parameter 1 to be a valid callback, class
'Drupal\fieldblock\Plugin\Block\FieldBlock' not found in
_drupal_render_process_post_render_cache() (line 3242 of
/var/www/drupal8/core/includes/common.inc).
30 19/Oct 00:07 system fieldblock module uninstalled.
It looks like the render cache still assumes that the module implementing the post render cache callback is still present. Rebuilding the cache (drush cr) solves the problem.
I expect Drupal to keep working (without the added functionality of the uninstalled module, obviously) after uninstalling a module. I am labeling this as major because it's pretty common use case, there is no helpful error message, and for people not using drush there is no good way to solve the problem.
Proposed resolution
I guess the best solution would be to automatically invalidate the render cache of objects affected by the uninstalled module. However I'm not sure if we actually have enough information to do that. Alternatively, we might be able to check if the post render cache callback still exists before trying to call it.
Remaining tasks
- Figure out the best approach for a fix.
- Make it work.
- Add tests?
User interface changes
none
API changes
none