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
Comment #2
fagoWe 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?
Comment #3
BenK commentedSubscribing
Comment #4
hgurol commentedSubscribing
Comment #5
hgurol commentedI 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...
Comment #6
fagorules-is-new-node.patch queued for re-testing.
Comment #7
klausiMini patch that fixes the most urgent node_insert event.
Comment #8
hgurol commentedpatch @#7 does solve my immediate problem.
thank you...
Comment #9
fagoMarked #999372: PDOException when creating new content with a new path alias. as duplicate.
Comment #10
klausiNew 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.
Comment #11
fagoPatch looks good to me, however user_save() also supports the is_new flag. So we'll need to fix it there too.
Comment #12
klausiYes, 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.
Comment #13
fagoI see. Thanks, committed.
Comment #14
sadeh commentedSubscribing
Comment #16
giorgio79 commentedTried 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.
Comment #17
longpt commented#10: 1068168-rules-node-insert-save.patch queued for re-testing.
Comment #18
Fred75 commentedHello 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:
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
Comment #19
mackpipe1 commentedI 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) VALUEScan you help me please
Comment #20
nicodv commentedSame 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).
Comment #21
nicodv commentedSorry 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
Comment #22
nicodv commentedI 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
Comment #23
nicodv commentedOk, 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.
Comment #24
ShawnNYC commentedAlso 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.
Comment #25
mitchell commented#23 and #24 describe this as being fixed.
Comment #27
my-family commentedSorry, it is not fixed - #23 and #24 are only a workaround. It is still an important bug in Rules module.
Comment #28
fagoThat 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.
Comment #29
aanugula commentedBelow 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);
Comment #30
salvis#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.