Execute node serialization inside new render context

Created on 14 June 2023, over 1 year ago

Problem/Motivation

We have recently found an issue in a client project where content saved with the node form was correctly published in AppleNews, but the same content, when scheduled to be published in background (in this case through the Scheduler module) didn't end up published upstream (although it was published in Drupal). After some troubleshooting, we discovered that the serialization process was failing in certain scenarios, due to a few ::render() calls we had in custom code.

While we fixed these calls and started using ::renderPlain() where appropriate, we believe it could be a good idea to wrap the full serialization call in ApplenewsManager::getDocumentDataFromEntity() in a ::executeInRenderContext() to prevent other contrib or custom code falling into this same issue again. This would act as a safety net to any process outside of a render context that deals with serializing parts of the finished HTML.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

RTBC

Version

1.0

Component

Code

Created by

🇪🇸Spain marcoscano Barcelona, Spain

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

Comments & Activities

  • Issue created by @marcoscano
  • Issue was unassigned.
  • Status changed to Needs review over 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.0.7 + Environment: PHP 7.4 & MySQL 5.7
    last update over 1 year ago
    Composer require failure
  • 🇪🇸Spain marcoscano Barcelona, Spain
  • Status changed to RTBC over 1 year ago
  • e0ipso Can Picafort

    I think this patch is pretty safe.

    Note that the current patch is incredibly difficult to add a test for, since it only fails when there is no render context, and one of the serializers calls ::render().

    However, a quick spot-check of similar services in core shows that this is a common practice (like MailerManager, and RestExport). They are similar in the sense that they serialize entities into HTML and might be executed in the background.

Production build 0.71.5 2024