I'm experimenting a constraint violation in a custom action at the node save of new node. The error is:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '112-0-domain_id' for key 'PRIMARY': INSERT INTO {node_access} (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5); Array ( [:db_insert_placeholder_0] => 112 [:db_insert_placeholder_1] => domain_id [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => 1 [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 1 ) in node_access_write_grants() (line 3335 of node.module).
There are other persons experimenting this issue when Rules and Domains are installed.
https://drupal.org/node/1140158#comment-4399872
To reproduce the bug follow the next steps:
- Install Rules and Domains module.
- Create a Rule thar reacts to node creation and that execute an action with auto node save.
- Create a new node and the exception will raise. The Domain module is not the root cause i traced the reasons an proposed a patch to the core team. http://drupal.org/node/1146244
Only happens when Rules interact with one or more modules that implement hook_node_grants because node_access_write_grants functions is called.
I cant figure other way to fix without D7 core patch but maybe is possible to create a fix at Rules layer.
Comments
Comment #1
fagoouch, I responded to #1146244: node_access integrity constraint violation on module_invoke_all('node_' . $op, $node);.
Comment #2
fagoComment #3
fagomarked #1212612: Integrity constraint violations when saving a new node + using node access modules as a duplicate.
Comment #4
fagomarked #1299368: Before Saving Content Reaction Rules not Firing as a duplicate
Comment #5
blackclover CreditAttribution: blackclover commentedThat was one example of the most recent instance. The before saving content trigger going away has happened to me on at least 5 occasions and this is the first time I have gotten that particular error.
Any idea what table is blocking the before saving event trigger as I lose significant work every time I restore? I had to go back 2 days to get it working again this time.
Comment #6
blackclover CreditAttribution: blackclover commentedAlso noticed that the after updating existing content trigger went away this time.
Comment #7
danielw CreditAttribution: danielw commentedSubscribing... the 'Before Saving new Content' trigger has disappeared from my list of triggers, and I'm getting the constraint violation on 'After Saving new Content' rules
Comment #8
enrikito CreditAttribution: enrikito commentedSubscribe
Comment #9
ciones CreditAttribution: ciones commentedthe patch in http://drupal.org/node/1146244#comment-5396916 worked for me when create new domain after saving certain content type.
Thank you
Comment #10
mitchell CreditAttribution: mitchell commentedPer #9.
Comment #11
Dean Reilly CreditAttribution: Dean Reilly commentedHi Mitchell,
I'm currently working on the core issue linked to in #9. I just wanted to point out that it's probably a bad idea to use that patch as it doesn't solve the problem for content update hook only insert hooks and also has a small bug that can result in unnecessary blank roles being written to the database.
The problem is basically that the insert and update hooks fire slightly too early. This has been fixed in D8 where they've been moved to fire after access information has been written. Moving hooks around in D7 is probably a bad idea so the latest patch introduces two new hooks (post_insert and post_update) which can be used instead in this situation.
Obviously this is a core issue so this ticket can probably be closed as duplicate, but if the new set of hooks does make it into core I'll reopen this ticket with a patch to add in the new rules triggers.
Best wishes,
Dean
Comment #12
mitchell CreditAttribution: mitchell commented> if the new set of hooks does make it into core I'll reopen this ticket with a patch to add in the new rules triggers.
K, so postponed for now.
Dean, thank you for keeping this issue on track and for working on the core solution.
Comment #13
fagoImproving title.
Comment #14
girishmuraly CreditAttribution: girishmuraly commentedJust an update that the latest patch https://drupal.org/node/1146244#comment-7290062 in the core issue is currently working.
Comment #15
my-family CreditAttribution: my-family commentedI tested the core patch mentioned in #14 and can confirm that it solved the problem for me.
Comment #16
deggertsen CreditAttribution: deggertsen as a volunteer commentedI'm not sure what the status of this issue should be, but seeing as the core issue is now fixed I figure this should no longer be postponed.
Comment #17
TR CreditAttribution: TR commentedThe core issue #1146244: node_access integrity constraint violation on module_invoke_all('node_' . $op, $node); cited by @fago in #1 was fixed and committed to Drupal core on 1 January 2014.
#14 and #15 tested with the core patch in that issue, and both reported that it fixed this issue.
There have been no further posts here since the core issue was resolved.
Because it has been almost 5 years since the core issue was resolved and no one has posted since to say they're still experiencing this issue, I'm going to assume it was fixed by that core patch.
If you continue to have this issue, feel free to re-open this with a complete description of the problem you are having and details about how to reproduce the problem.
Comment #18
TR CreditAttribution: TR commented