Impossible to update an entity revision if the field value you are updating matches the default revision.

Created on 9 March 2017, over 7 years ago
Updated 9 September 2023, 10 months ago

Problem/Motivation

Use case:

  1. Doing a batch update of all entity revisions to fix some field values (all revisions must be fixed because of content moderation, drafts and published revisions need to be updated).
  2. Iterate over all revisions, update entity value and call save.
  3. Encounter the following code in \Drupal\Core\Entity\Sql\SqlContentEntityStorage::saveToDedicatedTables:
          // When updating an existing revision, keep the existing records if the
          // field values did not change.
          if (!$entity->isNewRevision() && $original && !$this->hasFieldValueChanged($field_definition, $entity, $original)) {
            continue;
          }
    
  4. At this stage $original refers to the default entity revision. Forward non-default revisions are updated in order, after their predecessors.
  5. Since the revision $original has already been updated in the batch to our new value $entity->my_field === $original->my_field, so the saving is skipped.
  6. My revision is now stuck with a field value that can never be updated.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

10.1 ✨

Component
EntityΒ  β†’

Last updated about 15 hours ago

Created by

πŸ‡¦πŸ‡ΊAustralia Sam152

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024