In the course of updating Lightning's bundled version of Multiversion from alpha10 to alpha12, I discovered this bug.

Here is how it manifested, under alpha11 and later:

1. Create a new node.
2. Create a couple of new revisions of that node.
3. Visit the Revisions tab.
4. Weep bitterly as you realize that only the first revision is showing up in the list.

I chased this through the translation system and discovered what's happening here. The problem is in ContentEntityStorageTrait::doPreSave(). Specifically, this elseif clause:

    elseif (!$entity->isNew() && !isset($entity->original)) {
      $entity->original = $entity;
    }

The translation system is a terrifying labyrinth to me, but these lines are ultimately causing the entity's revision_translation_affected flag to be set incorrectly. Because of that, the Revisions tab -- which only displays revisions that changed in the current language -- is not showing everything it should.

The fault actually occurs in ContentEntityStorageBase::populateAffectedRevisionTranslations(). It calls $translation->hasTranslationChanges(), which is returning a false negative because...the original entity is the same as the updated entity, so of course there are no changes! All because that sneaky elseif clause made it so.

I'm attaching a patch which fixes this -- if $entity->originalId is set, it will load that one, unchanged. Otherwise, it'll do a standard loadUnchanged() with the current entity ID. That way, the translation system will not diff inaccurate data, and all flags will (as far as I know) be set correctly.

P.S. @timmillwood pointed me to #2597516: Remove unnecessary clone and #2792617: Issue with uuid filter, which may provide some clues as to why this breaking change was introduced in the first place.

CommentFileSizeAuthor
#2 2825477-2.patch843 bytesphenaproxima

Comments

phenaproxima created an issue. See original summary.

phenaproxima’s picture

StatusFileSize
new843 bytes

Behold, the patch.

phenaproxima’s picture

Status: Active » Needs review

Oh, but please do review it, kindly maintainers :)

phenaproxima’s picture

Issue summary: View changes
phenaproxima’s picture

Issue summary: View changes
phenaproxima’s picture

Issue summary: View changes
jeqq’s picture

Status: Needs review » Needs work

Thank you @phenaproxima for reporting this. I will review/test it, but I'm pretty sure that it will break the replication when using the Replicate/Relaxed/Deploy modules. Because of this we had #2792617: Issue with uuid filter.

As I remember we have this error: Fatal error: Call to a member function hasTranslation() on null in core/lib/Drupal/Core/Field/Plugin/Field/FieldType/ChangedItem.php when $this->loadUnchanged($entity->originalId ?: $entity->id()) returns null(can be reproduced during replication).

  • jeqq committed 9642c53 on 8.x-1.x authored by phenaproxima
    Issue #2825477 by phenaproxima, jeqq: ContentEntityStorageTrait uses...
jeqq’s picture

Status: Needs work » Fixed

@phenaproxima I couldn't reproduce the bug I mentioned, so I've committed this. At least it's a better solution than using the current entity as original. Thank you!

phenaproxima’s picture

Status: Fixed » Needs work

Thanks for committing it, @jeqq. I'm going to re-open this for test coverage.

JamesK’s picture

Thanks for tracking down that revisions issue, but this change reintroduces a bug like #2792617: Issue with uuid filter
Basically, we again end up with a case sometimes where $entity->isNew() returns FALSE but $entity->original is not set.

Would it break the revisions list to add back something like this after your changes?

if (!$entity->isNew() && !isset($entity->original)) {
  $entity->original = $entity;
}
JamesK’s picture

My bug is fixed by #2835880: Workspace mismatch during replication
Leaving issue as Needs work for tests.