ContentEntityBase::getLoadedRevisionId() returns NULL in some circumstances

Created on 30 March 2019, over 5 years ago
Updated 13 February 2023, almost 2 years ago

Problem/Motivation

Not sure if this is something particular to my installation, but after upgrading core from 8.6.13 to 8.7.0-beta1, a node save operation started throwing warnings of type:

Trying to get property 'value' of non-object

at

\Drupal\content_moderation\Plugin\Validation\Constraint\ModerationStateConstraintValidator::getOriginalOrInitialState()

/var/www/html/docroot/core/modules/content_moderation/src/Plugin/Validation/Constraint/ModerationStateConstraintValidator.php line 160

Stepping there with the debugger shows that when the error is thrown, $original_entity is empty, and that is because $entity->getLoadedRevisionId() some lines above also returns NULL.

See below the full trace, in case it helps.

Proposed resolution

Not sure why in the \Drupal\content_moderation\Plugin\Validation\Constraint\ModerationStateConstraintValidator::isFirstTimeModeration() some lines below, the $original_entity is retrieved differently. It seems like using the same approach in the ::getOriginalOrInitialState() method is enough to solve the issue. I ignore however if this is just a band-aid to hide the issue or it could be a legitimate fix.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Closed: outdated

Version

9.5

Component
Content moderation 

Last updated 24 days ago

Created by

🇪🇸Spain marcoscano Barcelona, Spain

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • 🇳🇿New Zealand quietone

    Steps to reproduce this problem were asked for 4 years ago and they have not been provided. That information is needed to investigate here. So, I think it is time to close. Because @mikelutz said that code moved around I am closing this as outdated.

    If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").

Production build 0.71.5 2024