Execute node serialization inside new render context

Created on 14 June 2023, about 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 about 1 year ago
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.0.7 + Environment: PHP 7.4 & MySQL 5.7
    last update about 1 year ago
    Composer require failure
  • πŸ‡ͺπŸ‡ΈSpain marcoscano Barcelona, Spain
  • Status changed to RTBC about 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.69.0 2024