I have a simple hook_post_update function which fails with the following error:
[notice] Update started: ssc_custom_post_update_9001
[error] LogicException: Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_render instead. in Drupal\Core\Render\Renderer->doRender() (line 244 of E:\www\myssc\html\core\lib\Drupal\Core\Render\Renderer.php). [error] Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_render instead. [error] Update failed: ssc_custom_post_update_9001
In ProcessBase.php line 171:
Unable to decode output into JSON: Syntax error
[ERROR] [node] [2022-03-12T04:58:35] LogicException: Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_re nder instead. in Drupal\Core\Render\Renderer->doRender() (line 244 of E:\www\myssc\html\core\lib\Drupal\C ore\Render\Renderer.php). | uid: 0 | request-uri: http://default/ | refer: | ip: 127.0.0.1 | link:
{ "0": { "ssc_custom": { "9001": { "#abort": { "success": false, "query": "Drupal\Core\Entity\EntityStorageException: Ren der context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use re nderPlain()/renderRoot() or #lazy_builder/#pre_render instead. in Drupal\Core\Ent
ity\Sql\SqlContentEntityStorage->save() (line 810 of E:\www\myssc\html\core\lib\Drupal\Core\Entity\Sql\SqlContentEntityStorage.php)." } } }, "#abort": [ "ssc_custom_post_update_9001" ] }, "drush_batch_process_finished": true }
I have stripped the code down to the bare minimum:
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\node\NodeInterface;
function ssc_custom_post_update_9001(&$sandbox) {
/** @var \Drupal\node\NodeStorageInterface $node_storage */
$node_storage = \Drupal::entityTypeManager()->getStorage('node');
// How many entities to processed per batch.
$limit = 5;
$node_ids = $node_storage->getQuery()
->accessCheck(FALSE)
->condition('type', 'article')
->range(0, $limit)
->execute();
// Load entities.
$nodes = $node_storage->loadMultiple($node_ids);
/** @var \Drupal\node\NodeInterface $node */
foreach ($nodes as $node) {
$node->setNewRevision();
$node->save();
}
$sandbox['#finished'] = 1;
}
If I run the same code directly (not from drush updb) it runs fine. Running from the admin menu "Run updates"; it also fails (so it is not a drush issue).
Commenting out the $node->save() and the error does not occur.
hook_deploy_N
running after configuration import when executingdrush deploy
.