[update] Thanks quietone, my apologies I was unaware of the AI disclosure policy. AI was used for this issue summary, but I verified it all, and it's suggested fix is currently in use on my site. [/update]

Problem/Motivation

The fix committed in #3035992: Stale values can be displayed by the Layout Builder UI but are saved correctly introduced a regression in LayoutOverrideFieldHelper::updateTempstoreEntityContext(). When a node is edited via the normal edit form while a Layout Builder tempstore exists, the method replaces the stored entity context with the post-save entity object. This post-save entity carries a new revision ID (because the node edit created a new revision), but the OverridesSectionStorage was originally loaded against the previous revision.

When the user subsequently clicks "Revert to defaults," RevertOverridesForm::submitForm() calls $this->sectionStorage->removeAllSections()->save(), which internally calls $this->getEntity()->save(). SqlContentEntityStorage detects the revision ID mismatch between the entity's claimed revision and the loaded revision, and throws:

Drupal\Core\Entity\EntityStorageException: Update existing 'node' entity
revision while changing the revision ID is not supported.

Environment: Drupal 11.x-dev. Also reproduced on Drupal 10.6.7 with the #3035992 patch backported.

Steps to reproduce

  1. Enable Layout Builder on a content type with "Allow each content item to have its layout customized" checked (e.g., at /admin/structure/types/manage/page/display/default)
  2. Create a node of that type with body text "original" and save it
  3. Open the node's Layout Builder page at /node/1/layout — this creates a tempstore entry via the PrepareLayout event subscriber
  4. Navigate away from Layout Builder without clicking "Save layout" or "Discard changes" (e.g., click the "View" tab or use the browser back button)
  5. Edit the node at /node/1/edit, change the body text to "updated", and save
  6. Open /node/1/layout again — the updated body text "updated" is correctly displayed (the #3035992 fix is working)
  7. Click "Revert to defaults" and confirm

Expected behavior: The layout reverts to the default display and redirects to the node view showing the current field values.

What happened instead: An uncaught EntityStorageException is thrown:

Drupal\Core\Entity\EntityStorageException: Update existing 'node' entity
revision while changing the revision ID is not supported.
in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save()

Full stack trace:

SqlContentEntityStorage->save() (line 815)
EntityBase->save() (line 370)
OverridesSectionStorage->save() (line 331)
RevertOverridesForm->submitForm()
FormSubmitter->executeSubmitHandlers()
FormSubmitter->doSubmitForm()
FormBuilder->processForm()
FormBuilder->buildForm()
FormController->getContentResult()

Proposed resolution

In LayoutOverrideFieldHelper::updateTempstoreEntityContext(), instead of assigning the post-save entity directly, reload the entity fresh from storage using EntityStorageInterface::load(). This returns the current default revision with all internal state (revision ID, original values, loaded revision tracking) fully consistent with the database. Then copy only the layout field from the tempstore to preserve in-progress layout changes.

Replace:

$updated_entity = $entity;
$updated_entity->{OverridesSectionStorage::FIELD_NAME} = $stored_entity->{OverridesSectionStorage::FIELD_NAME};

With:

$entity_storage = \Drupal::entityTypeManager()->getStorage($entity->getEntityTypeId());
$updated_entity = $entity_storage->load($entity->id());
$updated_entity->{OverridesSectionStorage::FIELD_NAME} = $stored_entity->{OverridesSectionStorage::FIELD_NAME};

Issue fork drupal-3586795

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

leevh created an issue. See original summary.

quietone’s picture

Title: EntityStorageException when reverting layout to defaults after entity field values updated via #3035992 fix » [regression] EntityStorageException when reverting layout to defaults after entity field values
Version: 11.3.x-dev » main
Issue summary: View changes
Related issues: +#3035992: Stale values can be displayed by the Layout Builder UI but are saved correctly

To me, this read like an AI tool was used to generate the issue summary. If so, the policy on the use of AI when contributing to Drupal includes that the use of AI must be disclosed. I suggest reading that to be aware of the expectations of the Drupal community and the consequences for violations of the policy.

Issues for Drupal core should be targeted to the 'main' branch, our primary development branch. Changes are made on the main branch first, and are then back ported as needed according to the Core change policies. The version the problem was discovered on should be stated in the issue summary Problem/Motivation section. Thanks.

Changing title per Special titles.

leevh’s picture

Issue summary: View changes
leevh’s picture

Issue summary: View changes

ishani patel made their first commit to this issue’s fork.

danielveza made their first commit to this issue’s fork.

danielveza’s picture

Priority: Normal » Major
Status: Active » Needs review

Confirming that this is an issue. I was able to replicate it on vanilla core & the MR does fix it. This was missing test coverage so I've added it.

IMO this should also be a Major, considering it's pretty easy to get into this situation and difficult to get out of it without knowing what you're doing. Updating the status to reflect that

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Bug Smash Initiative

Since I can't run test-only jobs with my role ran locally

Behat\Mink\Exception\ResponseTextException: The text "The first node body" was not found anywhere in the text of the current page.
/var/www/html/vendor/behat/mink/src/WebAssert.php:907
/var/www/html/vendor/behat/mink/src/WebAssert.php:293
/var/www/html/core/tests/Drupal/Tests/WebAssert.php:991
/var/www/html/core/modules/layout_builder/tests/src/Functional/LayoutBuilderOverridesTest.php:303

Shows the coverage.

Manually testing following the steps the bug does appear to be addressed.

No feedback to give. LGTM.