Problem/Motivation

After a recent site upgrade to Drupal 10, I am unable to update existing content using the Book content type. When pressing save on the node edit page, I receive the following error message:

Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '2535' for key 'PRIMARY': INSERT INTO "book" ("nid", "bid", "pid", "weight", "depth", "p1", "p2", "p3", "p4", "p5", "p6", "p7", "p8", "p9")

After some investigation, I discovered that when the node form is submitted, the existing book information ($node->book) is not present, so Book is trying to insert new rather than update existing data. This data is normally loaded in the book_node_load() function.

I see that conflict_entity_prepare_form replaces the node with one loaded earlier from storage. The problem is that book_node_load is called AFTER conflict_entity_load, so the copy of the node that Conflict saves to storage does not have book information attached...

Proposed resolution

Make sure conflict saves the entity after all hook_ENTITY_TYPE_load hooks have been run ?

Issue fork conflict-3510900

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

grahamc created an issue.