Call to \Drupal::service('renderer')->fails in CLI

Created on 31 October 2023, about 1 year ago

Problem/Motivation

revision_log_default.module lines 144-145 use \Drupal::service('renderer')->render to render inline templates, however when node->save is called programatically via command line, such as in an update hook being fired via drush updb, this has no context and throws an exception:

 [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 245 of /opt/drupal/web/core/lib/Drupal/Core/Render/Renderer.php). 
Drupal\Core\Entity\EntityStorageException with message 'Render context is empty, because render() was called outside of a renderRoot() or renderPlain() call. Use renderPlain()/renderRoot() or #lazy_builder/#pre_render instead.'

Steps to reproduce

Create an update hook that fires a node->save, run via drush

Proposed resolution

Switch these render calls to renderPlain.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

1.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States R_H-L

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @R_H-L
  • First commit to issue fork.
Production build 0.71.5 2024