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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2825477-2.patch | 843 bytes | phenaproxima |
Comments
Comment #2
phenaproximaBehold, the patch.
Comment #3
phenaproximaOh, but please do review it, kindly maintainers :)
Comment #4
phenaproximaComment #5
phenaproximaComment #6
phenaproximaComment #7
jeqq commentedThank 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.phpwhen$this->loadUnchanged($entity->originalId ?: $entity->id())returnsnull(can be reproduced during replication).Comment #9
jeqq commented@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!
Comment #10
phenaproximaThanks for committing it, @jeqq. I'm going to re-open this for test coverage.
Comment #11
JamesK commentedThanks 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->originalis not set.Would it break the revisions list to add back something like this after your changes?
Comment #12
JamesK commentedMy bug is fixed by #2835880: Workspace mismatch during replication
Leaving issue as Needs work for tests.