When email sent via drush, render context is empty

Created on 16 September 2020, almost 4 years ago
Updated 28 February 2024, 4 months ago

Problem/Motivation

When used in conjunction with queue processing for mail, errors are thrown on render.

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

Install htmlmail & queue_mail
Send password reset email
Execute queue via drush queue-run queue_mail --time-limit=15
Error in rendering.

Proposed resolution

Pretty simple fix here, change render() to renderRoot()
As its final HTML and not part of another render context, this shouldn't be an issue?

Remaining tasks

None

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Needs review

Version

3.0

Component

Module compatibility

Created by

πŸ‡¦πŸ‡ΊAustralia AlMunnings Melbourne

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΈπŸ‡¦Saudi Arabia samaphp Riyadh, SA πŸ‡ΈπŸ‡¦

    It seems a real major issue for those who sending email messages using queue_mail.
    It seems a well-known issue as per this link: https://www.drupal.org/project/drupal/issues/3085157 β†’

    We've tried the renderRoot() but there is no luck, still fails.
    We are using queue_mail module with this HTMLMail, so we had to come up with a workaround to execute the queue temporarily in a cronjob calling the browser URL from a controller to overcome this issue.

    $queueFactory = \Drupal::service('queue');
    $queueManager = \Drupal::service('plugin.manager.queue_worker');
    /** @var \Drupal\queue_mail\Plugin\QueueWorker\SendMailQueueWorker $queueWorker */
    $queueWorker = $queueManager->createInstance('queue_mail');
    /** @var \Drupal\Core\Queue\DatabaseQueue $queue */
    $queue = $queueFactory->get('queue_mail');
    if ($queue->numberOfItems() > 0) {
      // Get the number of items to process
      for ($i = 0; $i < $queue->numberOfItems(); $i++) {
        // Process the queue
        if ($item = $queue->claimItem()) {
          $workerResponse = $queueWorker->processItem($item->data);
          if (!empty($workerResponse) && !empty($workerResponse['result']) && ($workerResponse['result'] === TRUE)) {
            $queue->deleteItem($item);
          }
          else {
            // We will release it immediately.
            $queue->releaseItem($item);
          }
        }
      }
    }
    

    CAUTION: This should be used only in cases where there are not too many emails, this is not a scalable solution and should be used only for small/experimental sites.

Production build 0.69.0 2024