sql error when node_load() is called before type_local_nids_nodeapi() is called with $op = 'insert'
Cloudy - March 30, 2008 - 13:56
| Project: | Type-local nids |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | jbrown |
| Status: | closed |
Jump to:
Description
Clean install Drupal 6.1, php 5.2.2, MySQL 4.1.22.
I'm getting this warning when updating content created after installing the module.
user warning: Duplicate entry '4' for key 1 query: INSERT INTO node_lnid SET nid = 4, lnid = 2 in /home/cl0udy/www/swings/modules/type_local_nids/type_local_nids.module on line 44.
Seems like if(!$node->lnid) [line 65] is always returning true so _type_local_nids_generate_lnid is always called when a node is updated.
Altering _node_form to include the type_local_nid fixed the issue for me. Patch attached does this.
| Attachment | Size |
|---|---|
| type_local_nids_update_error.patch | 880 bytes |

#1
Thanks for reporting this. I hadn't tested the 6.x version as much as the 5.x. It's now fixed in 6.x-1.2.
I just needed to ensure that the lnid is loaded during 'update', as it seems D6 does load the node before updating it.
#2
Automatically closed -- issue fixed for two weeks with no activity.
#3
Whenever the 'insert' operation is called the $node->lnid is false, causing the _type_local_nids_generate_lnid function call, that's not the expected behaviour. I change one line of code to load the 'lnid' property before 'insert' and 'update'.
<?php
function type_local_nids_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'load':
case 'insert': // this line was changed
case 'update':
$node->lnid = db_result(db_query("
SELECT lnid
FROM {node_lnid}
WHERE nid = %d
",
$node->nid
));
if(!$node->lnid)
_type_local_nids_generate_lnid($node);
return array('lnid' => $node->lnid);
case 'delete':
db_query("
DELETE FROM {node_lnid}
WHERE nid = %d
",
$node->nid
);
break;
}
}
?>
#4
Node insertion is the time when _type_local_nids_generate_lnid() should most definitely be called. Thats the whole point of the module.
There is no point in checking if a node has a lnid when it is being created as there is no way it could have one yet.
#5
Seems some modules (I'm looking at you og_subgroups) call node_load during hook_nodeapi() with $op = 'insert'.
http://drupal.org/cvs?commit=266288
#6
Automatically closed -- issue fixed for 2 weeks with no activity.