Closed (works as designed)
Project:
Drupal core
Version:
6.0-rc2
Component:
taxonomy.module
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
24 Jan 2008 at 03:48 UTC
Updated:
8 Sep 2011 at 16:14 UTC
I don't know if this is a bug or just a change in design. If the latter, I need to understand the change so I can fix my code.
Here's the important part of my code:
$new_cat = $form_values['new_cat'];
$term = array('name' => $new_cat,
'description' => 'suggested by '. $user->name .' ('. $user->uid .') on '. date('F j, Y'),
'vid' => $form_values['faq_vid'],
'weight' => 0,
'parent' => 0,
'tid' => NULL,
);
taxonomy_save_term($term);
$cert_tid = $term['tid'];
$node = array(
'type' => 'faq',
'body' => '', /* Empty string rather than null. */
'title' => $form_values['title'],
'taxonomy' => array($category => $term),
'created' => time(),
'uid' => $user->uid,
'name' => $user->name,
'status' => 0, /* Unpublished. */
'format' => 1, /* Default filter (filtered HTML) */
'comment' => variable_get('comment_faq', 0),
);
// Okay, let's get it done. Node_submit will prepare it and make it an object.
$node = node_submit($node);
node_save($node);
When the node is saved, taxonomy_node_save (line 690) tries to insert the nid, vid, and tid into term_node and gets a duplicate (key 1). This does not happen on 5.6.
Comments
Comment #1
nancydruComment #2
catchhttp://drupal.org/node/164532 - see the last few comments, the indexes were altered since RC2.
Please try again with HEAD.
Comment #3
nancydruHmm. How long before RC3?
I looked through the patch and there's not really any changes to term_node other than to delete some rows that I don't have.
When I create a new term and node, I'm getting the correct nid and vid set, but then it's creating term_node records with tid = 0, 1, AND the correct one.
Comment #4
nancydruNope, I found a fix, and I assume the problem: If you notice, $term is created as an array, not an object. Apparently this was okay in 5.x, but it's not in 6.x. I added a
$term = (object)$term;and the problem went away.Comment #5
nancydruComment #6
ordually commentedNancyDru, thanks much for posting your fix on this one in #4...I came across the same issue and your solution saved me a pile of time.