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

fago’s picture

Component: Rules Core » Rules Engine
Status: Active » Needs review
fago’s picture

Version: 7.x-2.0-beta1 » 7.x-2.x-dev
Status: Needs review » Active
fago’s picture

fago’s picture

blackclover’s picture

That 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.

blackclover’s picture

Also noticed that the after updating existing content trigger went away this time.

danielw’s picture

Subscribing... 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

enrikito’s picture

Subscribe

ciones’s picture

the patch in http://drupal.org/node/1146244#comment-5396916 worked for me when create new domain after saving certain content type.
Thank you

mitchell’s picture

Status: Active » Closed (duplicate)

Per #9.

Dean Reilly’s picture

Hi 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

mitchell’s picture

Status: Closed (duplicate) » Postponed

> 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.

fago’s picture

Title: Rules auto node save constraint violation at node_access » Integrity constraint violation at node_access when saving a node on node insert
Component: Rules Engine » Rules Core

Improving title.

girishmuraly’s picture

Just an update that the latest patch https://drupal.org/node/1146244#comment-7290062 in the core issue is currently working.

my-family’s picture

I tested the core patch mentioned in #14 and can confirm that it solved the problem for me.

deggertsen’s picture

Status: Postponed » Active

I'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.

TR’s picture

Status: Active » Fixed
Issue tags: -rules, -node_access, -constraint exception

The 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.

TR’s picture

Status: Fixed » Closed (fixed)