I have enabled all Workflow modules. Created and mapped workflow rules. When i try to create content i'm always getting
PDOException: SQLSTATE[23505]: Unique violation: 7 ERROR: duplicate key value violates unique constraint "site1_node_access_pkey": INSERT INTO site1_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); Array ( ) in node_access_write_grants() (line 3417 of /var/www/trg/modules/node/node.module).

When i disable workflow access module, im able to create content
please help

Comments

mmff’s picture

Hi,
@kdineshbe
I encountered exactly the same error. So, if you have found the solution, try to post it.
best regards,

adamtong’s picture

i encounter the same problem too!!!

please help

NancyDru’s picture

adamtong’s picture

I solved the problem with this patch:

http://drupal.org/node/1146244#comment-6644078

The reason of the access module break on "create" event when state change explained in the above node.

NancyDru’s picture

Priority: Major » Normal

So this is a core issue?

adamtong’s picture

Yes, I think so. it is mainly due to using rule to do some action and involve node_access. I am not sure whether it can be fine-tuned in the workflow access module.

from: http://drupal.org/node/1146244

1. In a create node form we add a new node
2. The execution will call for first time the node_save to store the new node.
3. When module_invoke_all('node_' . $op, $node); is invoked the rules module will react to an event and will execute an action, this action could want to store some data to the node and as consequence will invoque node_save or entity_save of type node.
4. This will call node_save function and here start the problem. The second execution will have created the node but not the node_access grants, the node will consider the second execution as an update and will call the node_access_acquire_grants($node, $delete); with $delete parameter as true but this was not created for the first execution of node_save.
5. The second call of node_save will be the first one in make a deletion of node_grants to guarantee the correct recreation and will execute:
DELETE FROM node_access WHERE (nid = :db_condition_placeholder_0)
and
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)
6. When the first call of node_save continue after the module_invoke_all will consider $delete parameter as false because $op = insert and $delete = $op == 'update' is false. Then node_access_acquire_grants($node, $delete) will not make the grants deletion before trying to insert the grants and this result in constraint violation because the second node_save was ahead with the node_access grants insertion.

Here the PDOException:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '157-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] => 157 [: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 3334 of /home/pablo/fiat-concesionarios/modules/node/node.module).

Lostboy22’s picture

Was getting error w/ 7.x-1.0, was tired of "Strict warnings" so installed -dev 2013-02-06

Starting getting similar message ( PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ) to all content add (regardless of workflow and role) after adding the following rule:

{ "rules_message_approval_unpublish" : {
    "LABEL" : "Message Approval UnPublish",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "workflow_rules", "rules" ],
    "ON" : [ "workflow_state_changed" ],
    "IF" : [
      { "NOT workflow_check_state" : { "node" : [ "node" ], "workflow_state" : { "value" : { "8" : "8" } } } }
    ],
    "DO" : [ { "node_unpublish" : { "node" : [ "node" ] } } ]
  }
}

Tweaked rule and error went away. Improved rule export is:

{ "rules_message_approval_unpublish" : {
    "LABEL" : "Message Approval UnPublish",
    "PLUGIN" : "reaction rule",
    "REQUIRES" : [ "rules", "workflow_rules" ],
    "ON" : [ "workflow_state_changed" ],
    "IF" : [
      { "node_is_published" : { "node" : [ "node" ] } },
      { "NOT workflow_check_state" : { "node" : [ "node" ], "workflow_state" : { "value" : { "8" : "8" } } } }
    ],
    "DO" : [ { "node_unpublish" : { "node" : [ "node" ] } } ]
  }
}

So: Don't "unpublish" a node that isn't "published".
Yes, same as #1421518: PDOException: SQLSTATE[23000]: Duplicate entry in {node_access} table: when assigning a workflow to the node
Hope this helps.

NancyDru’s picture

Status: Active » Closed (fixed)

This is apparently fixed.