I believe this is a bug because in #2771523: support host revision delete it says "As we are creating new revisions in sync." Plus, if a composite entity is defined as part of the host's data then the versions that exist in the host's old revisions should not be able to be changed. The latest revision of the host should therefore always be pointing to a unique revision of the composite entity that isn't pointed to by any of the host's other revisions.

In typical use this is handled by a widget in the paragraph's module, but it makes more sense to define the revision behaviour of composite entities in this module, and making sure each host revision points to a unique target revision without exception will make related features easier to implement.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jmuzz created an issue. See original summary.

jmuzz’s picture

Status: Active » Needs review
FileSize
1.08 KB

Don't have a solution yet, but this should show that the revisions aren't getting made.

Status: Needs review » Needs work

The last submitted patch, 2: err-new_revisions-2801321-2-test_only.patch, failed testing.

jmuzz’s picture

Status: Needs work » Needs review
FileSize
2.22 KB
johnchque’s picture

Can we get a test-only patch?

jmuzz’s picture

The test-only patch is in #2.

miro_dietiker’s picture

Priority: Normal » Major

Promoting.

As a side effect, you touch this area:

We discussed once that we are not properly doing the default revision handling now. But we also realised that we are not relying on the default revision until now.

Maintaining the default revision also really makes sense from a performance perspective. It is faster to load it as the entity cache works.
But the problem is, we currently always load by revision, which circumvents it as far as i know.

So as a result, when loading the paragraphs, we could check if the host isDefaultRevision and then load the default revision instead of a specific revision. This would get us the entity cache back.

Passing to Berdir to get more qualified feedback.

Berdir’s picture

Yes, I think that makes sense.

We have a separate issue for that already, we can discuss that there: https://www.drupal.org/node/2673076

now that we no longer save too many new revisions, there shouldn't be a blocker for trying to do that. Or we can also just try to push the core issues that are trying add static and persistent caching for revision loading. That would be even better.

  • miro_dietiker committed 19ee3c4 on 8.x-1.x authored by jmuzz
    Issue #2801321 by jmuzz: New host revisions do not always create new...
miro_dietiker’s picture

Status: Needs review » Fixed

Committing. Plus updating the other issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

miro_dietiker’s picture

Priority: Major » Critical
Status: Closed (fixed) » Needs work

People say, this issue commit broke Paragraphs.

If we revert this, we need another release to make Paragraphs pass again.

  • miro_dietiker committed 258e5fe on 8.x-1.x
    Revert "Issue #2801321 by jmuzz: New host revisions do not always create...
miro_dietiker’s picture

So i reverted. No release needed as the commit was after the last release.
We can discuss now how we can fix this cleanly.

Ginovski’s picture

Assigned: Unassigned » Ginovski
Status: Needs work » Needs review
FileSize
3.34 KB

Added an if/else for the parent::preSave.
The parent was also saving the entity, that is why there was an extra revision in paragraphs. With this patch, paragraphs tests don't fail.

Status: Needs review » Needs work

The last submitted patch, 16: new_host_revisions_do-2801321-16.patch, failed testing.

Berdir’s picture

We should have an explicit test for this here as well. We already have a composite test, we should be able to extend it so that the initial save doesn't result in more than one revision.

johnchque’s picture

I don't think we have to do all in ERR, we are in this issue moving almost all the revision management to this module thus there might be errors in Paragraphs (which should work based on this revision management in ERR).

So we have to remove the revision management in paragraphs to rely on ERR only.

Ginovski’s picture

Status: Needs work » Needs review
FileSize
1.89 KB
5.61 KB

Added an assertion for the revisions count.

Status: Needs review » Needs work

The last submitted patch, 20: new_host_revisions_do-2801321-20.patch, failed testing.

Ginovski’s picture

Status: Needs work » Needs review
Berdir’s picture

Status: Needs review » Reviewed & tested by the community
+++ b/err-new_revisions-2801321-5.patch
@@ -0,0 +1,26 @@
+diff --git a/src/Plugin/Field/FieldType/EntityReferenceRevisionsItem.php b/src/Plugin/Field/FieldType/EntityReferenceRevisionsItem.php
+index 8b25f4d..62a574f 100644
+--- a/src/Plugin/Field/FieldType/EntityReferenceRevisionsItem.php
++++ b/src/Plugin/Field/FieldType/EntityReferenceRevisionsItem.php
+@@ -248,7 +248,20 @@ class EntityReferenceRevisionsItem extends EntityReferenceItem implements Option
+    */
+   public function preSave() {
+     parent::preSave();
+-    if ($this->entity instanceof EntityNeedsSaveInterface && $this->entity->needsSave()) {

patch in patch, don't forget to remove that.

miro_dietiker’s picture

Status: Reviewed & tested by the community » Fixed
FileSize
1.12 KB
+++ b/src/Plugin/Field/FieldType/EntityReferenceRevisionsItem.php
@@ -247,9 +247,25 @@ class EntityReferenceRevisionsItem extends EntityReferenceItem implements Option
+    if ($this->hasNewEntity()) {
+      parent::preSave();
...
+    else {

parent::preSave should always be called except clearly expressed..
Berdir pointed out that hasNewEntity() should be called before though.

I changed, passing local. Committing.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

effulgentsia’s picture

I appreciate the original motivation behind this issue, but I think there are also good reasons to allow composite entities to not have a new revision generated when they have not been edited. I opened #3267490: Allow composite entities to opt out of creating duplicate revisions to explore if and how we want to support that.