Steps to reproduce: Create a new reaction rule with the event "Content has been saved", add an action "Set a data value", select "node:title" and add a random value. Create a new node and observe the following PDO error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '24' for key 'PRIMARY': INSERT INTO {node} (nid, vid, type, language, title, uid, status, created, changed, comment, promote, sticky, tnid, translate) VALUES ...

Attached is a patch that fixes the issue for nodes, however other entities such as users are terms may also be affected. A test case is also included, but it does not work at the moment. What am I doing wrong?

Comments

Component: Rules Core » Rules Engine
Status: Needs review » Needs work

The last submitted patch, rules-is-new-node.patch, failed testing.

fago’s picture

We need to manually invoke the cache clearing function, such that the static caches are cleared too - see the other reaction rules test.
Perhaps we could test that generically in the entity-CRUD related tests by using the entity_save action?

BenK’s picture

Subscribing

hgurol’s picture

Subscribing

hgurol’s picture

Priority: Normal » Major

I believe this is a major issue.

I havent tested the patch since it says auto-testing failed. Or, should I go ahead and test the patch?

Thanks...

fago’s picture

Status: Needs work » Needs review

rules-is-new-node.patch queued for re-testing.

klausi’s picture

Status: Needs review » Needs work
StatusFileSize
new296 bytes

Mini patch that fixes the most urgent node_insert event.

hgurol’s picture

patch @#7 does solve my immediate problem.
thank you...

fago’s picture

klausi’s picture

Status: Needs work » Needs review
StatusFileSize
new1.08 KB

New patch for node_insert with a working test. I had a look at the other core entities, they do not set a is_new flag and do not throw this error. Third party entities might be affected, but that should be a follow-up issue for the Entity API.

fago’s picture

Status: Needs review » Needs work

Patch looks good to me, however user_save() also supports the is_new flag. So we'll need to fix it there too.

klausi’s picture

Status: Needs work » Needs review

Yes, user_save() does support it, but hook_user_insert() does not receive an object with is_new set (because the account object is casted from the $edit array shortly before invoking the hook). Nothing to do here.

fago’s picture

Status: Needs review » Fixed

I see. Thanks, committed.

sadeh’s picture

Subscribing

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

giorgio79’s picture

Status: Closed (fixed) » Active

Tried the latest dev but I am still getting this integrity constraint violation crap.

In my case, I have custom actions that perform a node_save after saving a new content type. I get this error even if I set save => FALSE in hook rules info.

It only works if I uncomment the node_save in the custom action.

longpt’s picture

Status: Active » Needs review
Fred75’s picture

Hello all,

I think I have a similar problem.

Here is what I am trying to do: create a rule that changes the value of a field when a certain type of content is created by a user that has a certain role = when a user is logged in as a member of the website and he creates a new node, then a box is automatically checked so that the content does not need to go through the regular approval process.

Here is the error I get when I log in as a member and save a new node of the relevant type:

PDOException : SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '255-4-content_access_rid' 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), (:db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11), (:db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17); Array ( [:db_insert_placeholder_0] => 255 [:db_insert_placeholder_1] => content_access_rid [:db_insert_placeholder_2] => 4 [:db_insert_placeholder_3] => 1 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 0 [:db_insert_placeholder_6] => 255 [:db_insert_placeholder_7] => content_access_rid [:db_insert_placeholder_8] => 3 [:db_insert_placeholder_9] => 1 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 0 [:db_insert_placeholder_12] => 255 [:db_insert_placeholder_13] => content_access_author [:db_insert_placeholder_14] => 88 [:db_insert_placeholder_15] => 1 [:db_insert_placeholder_16] => 0 [:db_insert_placeholder_17] => 0 ) dans node_access_write_grants() (ligne 3392 dans ...\www\modules\node\node.module).

Apart from this nasty message, the rule works, since the box does get checked properly.

I feel I should mention another problem I have with rules, which might be linked : when navigating to the website with Chrome, I see the following error message after the footer and the closing tag:
Fatal error: Call to undefined function user_access() in .../www/sites/all/modules/rules/rules.module on line ...
This problem has already been reported here: http://drupal.org/node/1019646
But none of the suggested solutions work for me.

I am currently using Drupal 7.12 + Rules 7.x-2.1 (in production) and Rules 7.x-2.x-dev (on a test server); both configurations have the same errors.

Thank you a lot in advance for your attention and help. :)

Cheers,

Fred

mackpipe1’s picture

Version: 7.x-2.x-dev » 7.x-2.2

I have a problem with the module rules, I made a ruler with the event "After saving new content", with conditional content type = XX and the action "Set a data value" but when testing I get this creation error.

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '81-5-content_access_rid' for key 'PRIMARY': INSERT INTO {node_access} (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES

can you help me please

nicodv’s picture

Same here, a little bit desperate because I've spent half a day fighting with it, but happy to see there is something going on to solve it (thanks for the module -love rules- and thanks for future patch).

Trying to set a data value on an ER field and using event "after saving new content" and the error is similar to the ones above:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '8829-0-all' 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] => 8829 [:db_insert_placeholder_1] => all [:db_insert_placeholder_2] => 0 [:db_insert_placeholder_3] => 1 [:db_insert_placeholder_4] => 0 [:db_insert_placeholder_5] => 0 ) in node_access_write_grants() (line 3425 of /Applications/MAMP/htdocs/150812files/modules/node/node.module).

nicodv’s picture

Sorry for the last comment, I did everything in a fresh install and there is no such problem. What is causing it? dunno, but I can sleep well today.
I'm really thankful for everything drupal gives me.

Thank you guys

nico

nicodv’s picture

I take back what I said in the previous message (not the thankful staff): I ran the same rule this morning and the error pops up in this installation too, so it let me do it once but next time I execute that rule, it tries to create a duplicate of the node.

Someone can explain why?

thanks

nico

nicodv’s picture

Ok, another comment here (my apologies) I should have tried everything before posting anything here, but my rule with the after new content is created event works only when the created content is not published right away.

I'll stop now

cheers

UPDATE: I solved it (temporarily) by setting the content type to "not published", use a rule with the "After new content is saved" event, edit the field/s I want within that rule, save content (forcing) and as a last action (post-save) flag the node. Then, 'chained' to this rule, add a new rule using the event "when a node has been flagged" and the action: publish the node. I know the system is a little bit crappy but it works for me.

ShawnNYC’s picture

Also getting this error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '81-5-content_access_rid' for key 'PRIMARY': INSERT INTO {node_access} (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES....

After checking the Database, I found that the entry value "81" in the above example, is never actually entered.

In other words, the error is saying "I can't insert a row with a primary key value of "81" (also the node id) into the Node Access table, because it already exists. But when you create another node, it will enter itself with value of "82" instead of "81", which would be the next unused node number. A

Like others have mentioned, this seems to happen because Rules is trying to do the action twice, or something similar.

If I had to guess, I think Rules might be executing "After saving new content" both before and after saving new content.

My Solution: Use "Before saving new content" instead of "After saving new content" and it works fine.

mitchell’s picture

Status: Needs review » Fixed

#23 and #24 describe this as being fixed.

Component: Rules Engine » Rules Core
Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

my-family’s picture

Status: Closed (fixed) » Active

Sorry, it is not fixed - #23 and #24 are only a workaround. It is still an important bug in Rules module.

fago’s picture

Status: Active » Closed (fixed)

That remaining issue is another problem for which we already have #1146248: Integrity constraint violation at node_access when saving a node on node insert - so let's keep this issue closed.

aanugula’s picture

Title: Auto saving of a new node after the event node_insert is broken » I have to save string value by using auto_save method in drupal?
Project: Rules » Devel
Version: 7.x-2.2 » 7.x-1.x-dev
Component: Rules Core » devel_generate
Assigned: Unassigned » aanugula
Category: bug » support
Status: Closed (fixed) » Active

Below code is working for array, but i want to save string value, but i am not getting exact syntax for that.

//oa_user_dob as arry it's working fine.
$account -> oa_user_dob = array(); $account -> oa_user_dob[] = $form_state['values'][10001]['dob'];
$account = user_save($account, array('oa_user_dob' => $account -> oa_user_dob));

//oa_user_dob as string it's not working.
$account -> oa_user_dob = $form_state['values'][10001]['dob'];
$account = user_save($account, $account -> oa_user_dob);

salvis’s picture

Title: I have to save string value by using auto_save method in drupal? » Auto saving of a new node after the event node_insert is broken
Project: Devel » Rules
Version: 7.x-1.x-dev » 7.x-2.2
Component: devel_generate » Rules Core
Assigned: aanugula » Unassigned
Status: Active » Closed (fixed)

#29 is neither a Rules nor a Devel issue.

Please do not grab a random post and add random comments and changes. Click on the Support link at the top of this page to see your support options.