Score:1

How to find module that is updating my node after insert

jp flag

When trying to create a new book i get the following message:

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

The problem here is the book is added twice. Therefor the book is created once and for the other one I get the message above.

For some reason the node creating is updated directly after creating it. This doesn't happen with a clean install with the book module. So it must be one of my custom or contrib modules doing this. Therefor the book module gives this error. To figure out where the problem comes from I wonder how I can see what module is updating the node after the insert.

Is it right that the only way the hook_node_update is called is by using the save() command in code? I trying to find this at this moment but none of the modules using this command seem to be the problem.

Can anyone help me with taking the next step in debugging this problem?

leymannx avatar
ne flag
Check contrib and custom modules for hook_entity_insert, hook_book_insert hook_entity_presave, hook_book_presave etc. and $entity->save(), $book->save() etc.
Joost avatar
jp flag
So I look for a `save()` in side one of the hooks right?
leymannx avatar
ne flag
Ah yeah, save() in some custom hook_node_update sounds suspicious. This should probably rather happen in hook_node_presave with just set()
Joost avatar
jp flag
I looked at all my modules but there is no misplaced `save()` to be found. Is it possible to do it the other way around? Can I find out what modules...piece of code is updating my node?
leymannx avatar
ne flag
No idea right now. I'd probably start switching custom modules off one by one, then continue with contrib, until you found the culprit.
Joost avatar
jp flag
I'll try that approach thanks
Score:5
tr flag

You could implement hook_module_implements_alter to list all modules that implement a specific hook this way:

function myModule_module_implements_alter(&$implementations, $hook) {
  if ($hook === 'entity_insert') {
    // List of all modules names that implement hook_entity_insert.
    dump(array_keys($implementations));
  }
}
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.