- Issue created by @grahamC
- Merge request !153510900: Implement hook_node_load to prevent bad interaction with book module → (Open) created by grahamC
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...
Make sure conflict saves the entity after all hook_ENTITY_TYPE_load hooks have been run ?
Active
2.0
Code