Unable to update book nodes

Created on 4 March 2025, about 2 months ago

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 ?

🐛 Bug report
Status

Active

Version

2.0

Component

Code

Created by

🇬🇧United Kingdom grahamC Oxford, UK

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024