When trying to load a translation for a language not provided in the current revision of an entity you are met with the following fatal error.
Uncaught exception 'Error' with message 'Call to a member function wasDefaultRevision() on null'
in /docroot/core/modules/content_moderation/src/ModerationInformation.php
$latest_revision_id
is null because $storage->getLatestTranslationAffectedRevisionId
returns null if no revision affecting the specified translation could be found
The attached patch only changes the following:
if ($latest_revision_id != $default_revision_id) {
to
if ($latest_revision_id != $default_revision_id && $latest_revision_id != '') {
in core/modules/content_moderation/src/ModerationInformation.php
Comments
Comment #2
timmillwoodCan you reproduce this in a kernel test?
Comment #3
damondt CreditAttribution: damondt commented@timmillwood I don't know how to write a kernel test, but may be able to learn. Would it be intended to test the error or the patch? How would I submit it?
Comment #4
damondt CreditAttribution: damondt commentedI got some advice on writing tests, I'll see what I can do.
Comment #5
seanBJust had the same error! Since there are several reasons why
getLatestTranslationAffectedRevisionId()
can return NULL (it is even documented on the method), checking for it makes sense.Comment #6
seanBPatch and fail patch attached to test
ModerationInformation::hasPendingRevision()
.Comment #7
amateescu CreditAttribution: amateescu for Pfizer, Inc. commentedLooks great to me, I only found a small nitpick:
We could use
assertTrue()
andassertFalse()
here :)Comment #10
joseph.olstadwe're also observing this issue in a bilingual site (two languages), applied the core patch.
The above patch looks great, tests prove it.
Comment #11
joseph.olstadas requested
with the minor change from assertEquals to assertTrue
patch was rolled against 8.7.x
Comment #12
casaran CreditAttribution: casaran commentedThe path in #11 worked fine for me.
Comment #13
alexpottCommitted and pushed 5cbd58e6a3 to 8.8.x and 2a9029d981 to 8.7.x. Thanks!
Credited @amateescu for issue review.
Comment #17
joseph.olstad@alexpott thanks, great to see this fixed for 8.8.x AND 8.7.x, it was not easy to find this.