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?

CommentFileSizeAuthor
#4 node_authlink_2212479.patch1.2 KBalexh

Comments

joelpittet’s picture

Status: Active » Closed (cannot reproduce)

This is old with 2 followers, I'll close this in hopes you've worked through the issue. If not or someone else runs upon this, try checking if hook_node_insert gets called more than twice, and if please provide steps to reproduce the issue if possible.

Sounds a bit like a race condition, that we might be able to sort out but really need to know what conditions are causing before throwing fixes at it.

alexh’s picture

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.

joelpittet’s picture

Status: Closed (cannot reproduce) » Needs review

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

alexh’s picture

StatusFileSize
new1.2 KB

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

tunic’s picture

Status: Needs review » Closed (outdated)

I'm sorry but Drupal 7 is no longer supported so I'm closing this. Please feel free to reopen it if it applies to any of the supported releases.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.