Error with duplicate entry

Created on 6 March 2014, almost 11 years ago
Updated 9 January 2024, 12 months ago

Hey, I really need this module to work, And it works just like I need...

But often I get an error when creating a node....

Drupal just says "The website encountered an error", but in the log I can see this

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '283' for key 'PRIMARY': INSERT INTO {node_authlink_nodes} (nid, authkey, created) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2); Array ( [:db_insert_placeholder_0] => 283 [:db_insert_placeholder_1] => 22f67232f3be0c6204e786c42efb59f1b9c05afc0501054fb2ce2791da80bc82 [:db_insert_placeholder_2] => 1394142904 ) in node_authlink_node_insert() (line 242 of C:\Apache2.2\htdocs\abcbookingV3\sites\all\modules\node_authlink\node_authlink.module)

So somehow it tried to duplicate an id key? how can we fix this?

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇩🇰Denmark acoustika

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇦🇹Austria alexh

    Sorry to post in a closed issue. But I had the same issue and solved it, so I just want to share this with anybody who still would need it.

    The error occurred in my setup when using also the Media Bulk Upload module . I see that in that module entity_save is called three times, so I assume this is causing the multiple calls of hook_node_insert. Bulk Media Upload is unmaintained and I did not see how to fix the issue there.

    But I saw two issues in the hook_node_insert implementation of this module:

    1. It accepts a node ID instead of a node object as parameter and then adds the auth key to the non-existing node object. I did not check if it is ever called with a nid instead of a node, but it is easy to fix that by loading the node in such case.
    2. It says to generate the key only if not set, but then inserts it also when it was already set. This creates the PDOException when the hook is called twice, so I think also the db_insert statement should be conditional.

    Attached is a patch which addresses both issues and fixed the issue for me.

  • Status changed to Needs review over 1 year ago
  • 🇨🇦Canada joelpittet Vancouver

    Thanks for getting back can you attach the patch you planned?

  • 🇦🇹Austria alexh

    Sorry for forgetting to provide the patch file and for not noticing this for a long while...eventually, the patch is attached here.

Production build 0.71.5 2024