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
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.

AttachmentSize
type_local_nids_update_error.patch880 bytes

#1

jbrown - March 30, 2008 - 16:12
Assigned to:Anonymous» jbrown
Status:needs review» fixed

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

Anonymous (not verified) - April 13, 2008 - 16:14
Status:fixed» closed

Automatically closed -- issue fixed for two weeks with no activity.

#3

asmdec - August 28, 2009 - 17:36
Status:closed» needs review

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

jbrown - September 17, 2009 - 21:05
Status:needs review» closed

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

jbrown - September 22, 2009 - 17:31
Title:_type_local_nids_generate_lnid always called on node update» sql error when node_load() is called before type_local_nids_nodeapi() is called with $op = 'insert'
Version:6.x-1.1» 6.x-1.x-dev
Status:closed» fixed

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

System Message - October 6, 2009 - 17:40
Status:fixed» closed

Automatically closed -- issue fixed for 2 weeks with no activity.

 
 

Drupal is a registered trademark of Dries Buytaert.