hook_node_insert PDOException exception issue I am attempting to programmatically insert some field data when a new node is being created using the following code:

function mymodule_node_insert($node) {

    $dialects = array('en-AU', 'en-NZ', 'en-US');

    node_object_prepare($node);
    foreach ($dialects as $dialect) {
        $node-&gt;translations-&gt;data[$dialect]['entity_id'] = $node-&gt;nid;
        $node-&gt;translations-&gt;data[$dialect]['entity_type'] = 'node';
        $node-&gt;translations-&gt;data[$dialect]['revision_id'] = 3;
        $node-&gt;translations-&gt;data[$dialect]['language'] = $dialect;
        $node-&gt;translations-&gt;data[$dialect]['source'] = 'en';
        $node-&gt;translations-&gt;data[$dialect]['uid'] = 1;
        $node-&gt;translations-&gt;data[$dialect]['status'] = 1;
        $node-&gt;translations-&gt;data[$dialect]['translate'] = 0;
        $node-&gt;translations-&gt;data[$dialect]['created'] = time();
        $node-&gt;translations-&gt;data[$dialect]['changed'] = time();

        $node-&gt;field_page_body[$dialect] = $node-&gt;field_page_body['en'];
    }
    node_save($node);       
}


However, I recieve the following error:



I understand it's complaining about the same node ID being saved twice but I'm not sure how to avoid this exception and update my new node with the programmatically set data?

It's important I execute my code at hook_node_insert because there are hundreds of nodes to be imported later and they all need the same treatment.

The same code works when tested in mymodule_init().
You cannot call node_save($node) during hook_node_insert($node).

According to the documentation, that hook is invoked during the middle of the database transaction, so the node isn't committed to the database yet. So when you invoke node_save, the old node you're attempting to update doesn't exist yet, and it will attempt to create a new node (with the same ID). Thus, the collision.