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
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3001299-10.patch | 3.05 KB | joseph.olstad |
| #11 | interdiff_6_to_10_issue-3001299.txt | 1.92 KB | joseph.olstad |
| #6 | 3001299-6.patch | 2.79 KB | seanb |
| #6 | 3001299-6-fail.patch | 1.7 KB | seanb |
| core-translation-pending-revision.patch | 1.43 KB | damondt |
Comments
Comment #2
timmillwoodCan you reproduce this in a kernel test?
Comment #3
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 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 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 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.