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.

CommentFileSizeAuthor
type_local_nids_update_error.patch880 bytesCloudCuckoo

Comments

jbrown’s picture

Assigned: Unassigned » 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.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

asmdec’s picture

Status: Closed (fixed) » 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'.

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;
	}
}
jbrown’s picture

Status: Needs review » Closed (fixed)

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.

jbrown’s picture

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) » 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

Status: Fixed » Closed (fixed)

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