WSOD with PHP Error: Call to a member function getTranslation() on null

Created on 18 March 2023, over 1 year ago
Updated 3 April 2023, over 1 year ago

Problem/Motivation

When I add an Estimated Read Time Field to a node, when saving that node I get a WSOD (The website encountered an unexpected error. Please try again later.) It throws a PHP error in the log: "Call to a member function getTranslation() on null" at .../web/core/modules/node/src/NodeViewBuilder.php line 100.

This seems to be similar to the other WSOD issues 🐛 WSOD saving node if "Links" field is enabled on view mode Fixed but a little different.

Drupal 10
Field types on the page:
Token Field, Long Formatted Text Fields, Media Fields,

Revisions are turned on. (Might be related to other issue).

Steps to reproduce

Drupal 10 Fresh Install with Composer. Install Estimated Read time. Add Read Time field to Article. Create Article.

WSOD with same issues.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Closed: duplicate

Version

1.0

Component

Code

Created by

🇺🇸United States DrupalRanger

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

Comments & Activities

  • Issue created by @DrupalRanger
  • First commit to issue fork.
  • Status changed to Needs review over 1 year ago
  • 🇮🇳India Ranjit1032002

    Created a patch for the issue mentioned, please review.
    Thank You.

  • 🇺🇸United States DrupalRanger

    Thank you for the quick update. I tried the patch on a fresh install with Read Time added to the Article content type. PHP Error remains. The process of patching core modules is highly discouraged. Is this patch just to test the error origins?

  • 🇺🇸United States kevinquillen

    This is not an acceptable patch, this patches core.

    One workaround for now is to remove "Links" field from content displays on the Manage Display tab.

  • Status changed to Needs work over 1 year ago
  • 🇺🇸United States kevinquillen

    This is also happening in Drupal 9.

  • 🇺🇸United States kevinquillen

    It looks like at the time of node creation, the render service is trying to render a node but the node is not yet created:

          $storage = \Drupal::entityTypeManager()->getStorage('node');
          /** @var \Drupal\node\NodeInterface $revision */
          $revision = !isset($revision_id) ? $storage->load($node_entity_id) : $storage->loadRevision($revision_id);
          $entity = $revision->getTranslation($langcode)
    

    ;

    $revision is NULL, so trying to get its translation fails.

    The dev version of this module has the proper fixes (its a race condition I believe). The issue is here with an updated patch for translations: 🐛 Error on adding new translation Fixed

  • Status changed to Closed: duplicate over 1 year ago
  • 🇺🇸United States kevinquillen

    The dev branch will fix the immediate issue. Continuing in the other relevant issue. Closing as a duplicate of 🐛 Error on adding new translation Fixed

Production build 0.71.5 2024