Integrity constraint violation: Duplicate entry, node_revision

Created on 27 June 2023, over 1 year ago

Problem/Motivation

Manual merge conflict resolution may end up to

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'xxx' for key 'PRIMARY': INSERT INTO "node_revision"

Conflict module expects that the entity loaded from the storage remains unchanged while conflict resolution in progress. However, user a.ka content editor is able to save new revision of the entity while manual merge conflict resolution on-going in other browser or browser tab.

If the revision for the entity loaded from the storage is greater than the locally edited entity, conflict resolution will end up to duplicate revision_id error in core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php when entity revision is being saved.

Steps to reproduce

  1. Install Drupal 9
  2. Install and enable conflict module
  3. Log in as admin / editor
  4. Open article for edit in two tabs
  5. tab1: Edit title and Save
  6. tab2: Edit title and Save -> conflict, click "Resolve conflicts"
  7. tab1: Edit body and Save
  8. tab2: Tick "Manual merge completed" and Save -> error

Proposed resolution

Do not have proper solution proposal for this as of now.

However, in order to prevent duplicate error to happen for content editors, you could check (before setting revision id for the locally edited entity) whether revision has changed for the entity loaded from the storage in autoMergeEntityMetadata() and flag (or resolve) revision change.

🐛 Bug report
Status

Active

Component

Code

Created by

🇫🇮Finland mitrpaka

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

Comments & Activities

Production build 0.71.5 2024