I've got it each time when updating my node (type job-posting):

user warning: Duplicate entry '258-4033' for key 1 query: INSERT INTO term_node (nid, vid, tid) VALUES (1424, 4033, 258) in /home/sites/co.uk/public_html/modules/taxonomy/taxonomy.module on line 694.
user warning: Duplicate entry '259-4033' for key 1 query: INSERT INTO term_node (nid, vid, tid) VALUES (1424, 4033, 259) in /home/sites/co.uk/public_html/modules/taxonomy/taxonomy.module on line 694.
user warning: Duplicate entry '268-4033' for key 1 query: INSERT INTO term_node (nid, vid, tid) VALUES (1424, 4033, 268) in /home/sites/co.uk/public_html/modules/taxonomy/taxonomy.module on line 694.
user warning: Duplicate entry '272-4033' for key 1 query: INSERT INTO term_node (nid, vid, tid) VALUES (1424, 4033, 272) in /home/sites/co.uk/public_html/modules/taxonomy/taxonomy.module on line 694.
user warning: Duplicate entry '273-4033' for key 1 query: INSERT INTO term_node (nid, vid, tid) VALUES (1424, 4033, 273) in /home/sites/co.uk/public_html/modules/taxonomy/taxonomy.module on line 694.
user warning: Duplicate entry '276-4033' for key 1 query: INSERT INTO term_node (nid, vid, tid) VALUES (1424, 4033, 276) in /home/sites/co.uk/public_html/modules/taxonomy/taxonomy.module on line 694.

It's similar to: #20133: Latest taxonomy.patch and latest taxonomy (CVS) module result in error but I'm not using Taxonomy Access Control

Any suggestions?

CommentFileSizeAuthor
#52 duplicate_entry_for_taxonomy_sql_query-361509.patch603 byteschrisns
#22 autotag-1.17.patch658 bytesAnonymous (not verified)
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kenorb’s picture

        foreach ($term as $tid) {
          if ($tid) {
            db_query('INSERT INTO {term_node} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $tid);
          }
        }
Dave Reid’s picture

What other taxonomy-type modules are you using?

apaderno’s picture

Title: user warning: Duplicate entry '258-4033' for key 1 query: INSERT INTO term_node in taxonomy/taxonomy.module on line 694. » Duplicate entry for taxonomy.module SQL query
kenorb’s picture

Ad (enabled),
Taxonomy Autotagger (autotag) (enabled),
Forum (enabled),
Hierarchical Select Taxonomy (enabled),
Taxonomy translation (enabled),
Image Gallery (enabled),
Tagadelic (enabled),
Taxonomy Import/Export via XML (enabled),
Text Ad (enabled),
Advanced Forum (enabled),
Forum Thread (enabled)

Can be related to:
http://drupal.org/node/283358#comment-929341 (it's on 5.x)
I'm using 6.x.

kenorb’s picture

Project: Drupal core » Auto Tagging
Version: 6.9 »
Component: taxonomy.module » Code
apaderno’s picture

Project: Auto Tagging » Drupal core
Version: » 6.9
Component: Code » taxonomy.module

I would try to disable those modules one by one, and see when the problem disappear.

apaderno’s picture

Title: Duplicate entry for taxonomy.module SQL query » Duplicate entry for taxonomy SQL query
Project: Drupal core » Auto Tagging
Version: 6.9 »
Component: taxonomy.module » Code

I am sorry; it's the usual problem with adding two comments at the same time.

kenorb’s picture

Title: Duplicate entry for taxonomy SQL query » Duplicate entry for taxonomy.module SQL query
Priority: Normal » Critical

Yes, it's Auto Tagging problem.
After disabling it, problem disappears.

kenorb’s picture

Project: Auto Tagging » Taxonomy Autotagger
Version: » 6.x-1.x-dev
apaderno’s picture

Title: Duplicate entry for taxonomy.module SQL query » Duplicate entry for taxonomy SQL query
sdrycroft’s picture

Priority: Critical » Minor

Critical? Really, these look like warnings to me. I know what is causing them, and will find a fix at some point, for now, don't worry.

sdrycroft’s picture

Version: 6.x-1.x-dev » 6.x-1.17
Status: Active » Postponed (maintainer needs more info)

This may actually be fixed in the latest version. Can users please try it, and let me know if they still get the warnings as before, and if so, what they did to receive the warnings.

Thanks in advance.

Anonymous’s picture

Priority: Minor » Normal

They are may say warning but it is a misnomer. It is actually an error. IMO, though this is a bug with taxonomy_node_save() since it is that core function that is giving the error.

From what I can tell, when $node->taxonomy exists with data; this issue happens. Also, {autotag} table is always empty, should it contain data? I think what should happen is autotag needs to add the missing terms to $node->taxonomy and then node_save($node) rather than call taxonomy_node_save(). This is at least a normal priority.

Anonymous’s picture

@sdrycroft: Unable to tell if the issue is fixed because of #368520: table term_lowername doesn't exist.

Anonymous’s picture

Version: 6.x-1.17 » 6.x-1.16

I'm going crazy here. I can't see how this issue is the fault of autotag. The first thing that taxonomy_node_save does is call taxonomy_node_delete_revision which calls

  db_query('DELETE FROM {term_node} WHERE vid = %d', $node->vid);

Where does that go wrong? Debugging, more later.

Anonymous’s picture

I found the issue:

From taxonomy_node_save():

  if (is_array($terms)) {
    foreach ($terms as $term) {
      if (is_array($term)) {
        foreach ($term as $tid) {
          if ($tid) {
            db_query('INSERT INTO {term_node} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $tid);
          }
        }
      }
      else if (is_object($term)) {
        db_query('INSERT INTO {term_node} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $term->tid);
      }
      else if ($term) {
        db_query('INSERT INTO {term_node} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $term);
      }
    }
  }

And $terms contains:

	$terms:

Array
(
    [43] => stdClass Object
        (
            [tid] => 43
            [vid] => 1
            [name] => apparel
            [description] => 
            [weight] => 0
        )

    [36] => stdClass Object
        (
            [tid] => 36
            [vid] => 1
            [name] => men's
            [description] => 
            [weight] => 0
        )

    [1] => Array
        (
            [0] => 36
            [1] => 43
        )

)

Because $terms contains both the objects and an array of tids; taxonomy_node_save is saving the term_node data twice. So, the question now is, why does autotag do

  $term = $node->taxonomy;

in the autotag_nodeapi function? Should this only be done for 'insert' and not for 'update'?

sdrycroft’s picture

Apologies for taking some time to reply to this. Thanks for the work earnie, sadly I already knew that was the issue, but am now having difficulty in recreating it on my site. Can somebody please try 6.x-1.17 and let me know if they're still experiencing this, and if so, how to recreate the issue.

Cheers.

Anonymous’s picture

Version: 6.x-1.16 » 6.x-1.17

I installed the lowername module and upgraded to 1.17. Then I ran cron.php and still see this error.

Anonymous’s picture

Also, if $node->taxonomy exists and the tids include the tids autotag add then there is no reason to call taxonomy_node_save(). If autotag would add more then those should be added to $node->taxonomy instead of calling taxonomy_node_save(). Thinking further, IMO, $node->taxonomy should always be created and taxonomy_node_save should never be called.

Ah, yes, the weight of the autotag module just needs to come before the weight of the taxonomy module. Then it's hook_nodeapi implementation will take the $node->taxonomy object and pass it to taxonomy_node_save(). The weight of autotag module can be changed in the install/update procedures by modifying the row in the {system} table.

sdrycroft’s picture

I installed the lowername module and upgraded to 1.17. Then I ran cron.php and still see this error.

This shouldn't be anything to do with this module, as it has no hook_cron function.

Anonymous’s picture

No but feedAPI does and creates updates to existing nodes and inserts for new nodes causing the hook_nodeapi of this module to call taxonomy_node_save with duplicate data in the $terms array.

Anonymous’s picture

FileSize
658 bytes

Here's a patch that fixes the issue. This difference is against the 1.17 source.

Anonymous’s picture

Status: Postponed (maintainer needs more info) » Needs review

Duh

sdrycroft’s picture

Status: Needs review » Fixed

Cheers for this earnie. This has inspired me to also fix http://drupal.org/node/291846 , which will be included in 6.x-1.18.

Anonymous’s picture

I happen to think that I should have checked for is_object and is_array for the type of data in $term similar to what taxonomy_node_save does. Other modules might also badly add taxonomy. I'll create a different issue with a new patch unless you want to just take care of it.

sdrycroft’s picture

Thanks earnie, I've adapted your fix a little, although I don't feel that it is necessary to check if $node->taxonomy is_object.

Anonymous’s picture

Status: Fixed » Active

I'm still getting duplicates. I see duplicate tids in the $terms[$vid] array. I didn't catch it earlier because my feeds didn't fire due to timing.

The fix I propose is

      foreach ($terms as $vid => $tids) {
        $terms[$vid] = array_unique($tids);
      }
      taxonomy_node_save($node, $terms);
Anonymous’s picture

Version: 6.x-1.17 » 6.x-1.18

@sdrycroft: Your adaptation doesn't resolve the duplicate data in $terms and causes #370221: Object to string conversion error.

sdrycroft’s picture

Status: Active » Fixed

Please completely uninstall the previous version of Autotag, and install the latest 6.x-1.19 version. When posting bug reports, please ensure you post a list of all other contributed modules that are installed, and the exact steps required to reproduce the bug you're experiencing from a clean Drupal install.

Status: Fixed » Closed (fixed)

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

chrisbuck’s picture

Status: Closed (fixed) » Active

Receiving this error each time I use "Re-autotag by content type": "user warning: Duplicate entry '0-9' for key 1 query: INSERT INTO term_node (nid, vid, tid) VALUES (8, 9, 0) in /home/..../modules/taxonomy/taxonomy.module on line 701."

I'm using version 6x-1.27 and the following taxonomy modules:

Tagging 6.x-2.0-beta2
Tagging extractor suggestions 6.x-2.0-beta2
Tagging opencalais suggestions 6.x-2.0-beta2
Tagging vocabular suggestion 6.x-2.0-beta2

My settings are correct (i.e., "multiple" and "required"). Any help would be appreciated. I'm very interested in this module's development. Thanks.

apaderno’s picture

Version: 6.x-1.18 » 6.x-1.27

I am changing the referring version as per previous comment.

chrisbuck’s picture

Thanks. I'm following this thread - because the certain taxonomies aren't working correctly. Just a few. I consistently get this error, and it seems like certain tags are misapplied. For instance, the text string is something like "Dog" and it ends up tagging the node as "Cat."

tobiberlin’s picture

I also get this error when updating an existing node with tags in it - using Autotag 1.27, Lowername 1.1 and the following Taxonomy related modules:

Simplenews
Simplenews Actions
Simplenews Analytics
Simplenews Statistics
XML sitemap taxonomy
Forum Access
Forum

Taxonomy is latest version 6.16 and the error message mentions now another line:

user warning: Duplicate entry '201-1687' for key 1 query: INSERT INTO term_node (nid, vid, tid) VALUES (1670, 1687, 201) in /srv/www/vhosts/MY-SITE.com/httpdocs/modules/taxonomy/taxonomy.module on line 693.

The vocabulary is "tags" with multiple select - other constellations did not work for me.

tobiberlin’s picture

as there was no post for longer... does no one has this problem anymore??????

oldmoonlake’s picture

Yes, I am.
user warning: Duplicate entry '0-617' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (617, 617, 0) in /public_html/modules/taxonomy/taxonomy.module on line 701.
Taxonomy related module: Taxonomy hide, Taxonomy Menu, Taxonomy Node, Lowername

fuscata’s picture

I'm having the problem, perhaps with a slightly older version:
// $Id: taxonomy.module,v 1.414.2.12 2009/09/15 11:13:08 goba Exp $

Anyway, in this code:

/**
 * Save term associations for a given node.
 */
function taxonomy_node_save($node, $terms) {
...

  // Free tagging vocabularies do not send their tids in the form,
  // so we'll detect them here and process them independently.
  if (isset($terms['tags'])) {
...
        // Defend against duplicate, differently cased tags
        if (!isset($inserted[$typed_term_tid])) {
          db_query('INSERT INTO {term_node} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $typed_term_tid);
          $inserted[$typed_term_tid] = TRUE;
        }
      }
    }
  }

  if (is_array($terms)) {
    foreach ($terms as $term) {
      if (is_array($term)) {
        foreach ($term as $tid) {
          if ($tid) {
            db_query('INSERT INTO {term_node} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $tid);
          }
        }
      }
      else if (is_object($term)) {
        db_query('INSERT INTO {term_node} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $term->tid);
      }
      else if ($term) {
        db_query('INSERT INTO {term_node} (nid, vid, tid) VALUES (%d, %d, %d)', $node->nid, $node->vid, $term);
      }
    }
  }

It looks to me like the INSERT is performed twice if isset($terms['tags']). Am I right that changing this line:
if (is_array($terms)) {
to:
else if (is_array($terms)) {
fixes the problem?
EDIT: This causes problems when editing taxonomy from the GUI.

chrisbuck’s picture

Also getting the error at line 693 in taxonomy.module. I get this error from the log when trying to update an ipaper content type (note: I do have autotag module set to autotag the ipaper content type):

Duplicate entry '223-966' for key 1 query: INSERT INTO term_node (nid, vid, tid) VALUES (170, 966, 223) in /home/MYSite/public_html/Directory/modules/taxonomy/taxonomy.module on line 693."

Is this an issue with the taxonomy module, the autotag module or both?

sdrycroft’s picture

Version: 6.x-1.27 » 6.x-2.0
Status: Active » Fixed

This issue should be fixed in v2 of the module. Please re-open this issue if you're still experiencing any of the problems above.

ckreutz’s picture

Priority: Critical » Normal
Status: Active » Fixed

I have updated to the v2. But I still get the error.

Particular when I re-autotag, I get dozens of these errors:
Duplicate entry '41938-59316' for key 1 query: INSERT INTO term_node (nid, vid, tid) VALUES (59124, 59316, 41938) in //taxonomy.module in line 709.

Status: Fixed » Closed (fixed)

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

rkodrupal’s picture

Priority: Normal » Critical
Status: Closed (fixed) » Active

I set up one content type with only one taxonomy (keywords).
I ran autotag and it successfully updated the keywords tags
I re-ran autotag (as an Autotag on Save with a single node) and got a report log filled with entries similar to the following:

Duplicate entry '375-801' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (755, 801, 375) in C:\xampp\htdocs\modules\taxonomy\taxonomy.module on line 709.

each of the keywords that were already there from the first autotag had a corresponding error in the log report. it looks as though autotag is doing an insert instead of an update?

will make it difficult to update tags to reflect changes to the keywords taxonomy, since legitimate errors will be buried in amongst these illegitimate bastards.

protoplasm’s picture

Priority: Normal » Critical
Status: Fixed » Active

Exactly same issue. I am also getting double tags. I am going to have to go back to the old version for now. BTW, I love this module. Keep up the good work.

mkinnan’s picture

I receive the same errors when running the re-autotag at /admin/settings/autotag.

If I empty out the term_node table and run the re-autotag, it works great. Running the re-autotag a 2nd time results in the dozens of error messages.

kyen99’s picture

Seems like this is still an issue, although, it doesn't seem to be affecting functionality. subscribe!

tobiberlin’s picture

same here:

user warning: Duplicate entry '2076-1943' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (1926, 1943, 2076) in /var/www/vhosts/mysite/httpdocs/modules/taxonomy/taxonomy.module on line 709.
sdrycroft’s picture

Priority: Critical » Minor
deomurari’s picture

I have the same issue

Duplicate entry '11355-76' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (76, 76, 11355) in D:\xampp\htdocs\avian\modules\taxonomy\taxonomy.module on line 708.

llegal offset type in D:\xampp\htdocs\avian\modules\taxonomy\taxonomy.module on line 1042.

and some warning messages also...

warning: Illegal offset type in isset or empty in D:\xampp\htdocs\avian\modules\taxonomy\taxonomy.module on line 1038.
warning: Illegal offset type in D:\xampp\htdocs\avian\modules\taxonomy\taxonomy.module on line 1039.
warning: Illegal offset type in D:\xampp\htdocs\avian\modules\taxonomy\taxonomy.module on line 1042.
warning: Illegal offset type in isset or empty in D:\xampp\htdocs\avian\modules\taxonomy\taxonomy.module on line 1038.
warning: Illegal offset type in D:\xampp\htdocs\avian\modules\taxonomy\taxonomy.module on line 1039.
warning: Illegal offset type in D:\xampp\htdocs\avian\modules\taxonomy\taxonomy.module on line 1042.

Anonymous’s picture

Priority: Minor » Major

The problem seems to be that the taxonomy is specified twice in the modified node object, once as an already existing database object and once in as an array as I illustrate in #16. This is at least a major issue and certainly not minor.

sdrycroft’s picture

Priority: Major » Minor

Why is this major? Does your site crash? Does it stop the node from saving? Has data been lost?

Anonymous’s picture

Priority: Minor » Major

Pretty much makes your module unusable, yes.

chrisns’s picture

Please find attached patch for your consideration for merging (and for those like me that use drush_make in the mean time)
The issue arises when there are multiple fields/form parts that autotags are created from, duplicate tags are marked.
This patch in a very crude fashion, removes those duplicates.

senzaesclusiva’s picture

I have applied this patch, but it returns always this warning:

user warning: Duplicate entry '103-522' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (522, 522, 103) in /Applications/MAMP/htdocs/mysite/modules/taxonomy/taxonomy.module on line 716.
user warning: Duplicate entry '103-523' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (523, 523, 103) in /Applications/MAMP/htdocs/mysite/modules/taxonomy/taxonomy.module on line 716.
user warning: Duplicate entry '103-524' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (524, 524, 103) in /Applications/MAMP/htdocs/mysite/modules/taxonomy/taxonomy.module on line 716.
user warning: Duplicate entry '103-567' for key 'PRIMARY' query: INSERT INTO term_node (nid, vid, tid) VALUES (567, 567, 103) in /Applications/MAMP/htdocs/mysite/modules/taxonomy/taxonomy.module on line 716.
Etc........

the site does not crash and the update of the new nodes is still correct.

One request; it's possible to re-autotag ONLY NEW NODES? (infact this error appers because it attempts to update also the old nodes)

PS. I'm not very practical about Drupal API, but IMO may be there is something strange in autotag.module, line 96 ?:

foreach($tids as $tid){
          if(is_array($node->taxonomy[$tid['vid']])){
            $node->taxonomy[$tid['vid']][$tid['tid']] = $tid['tid'];
          }else{
            $node->taxonomy[$tid['vid']] = array(
              $tid['tid'] => $tid['tid']
            );
          }
        }
      }
      break;
    case 'update':
    case 'insert':
      // Here we can add the relevant tids to the autotag table.
      if(isset($_SESSION['autotag_tids'][$node->form_build_id])){
        // Lets get the ones that were tagged to the node from the term_node table
        $result = db_query('SELECT n.tid, t.vid FROM {term_node} n, {term_data} t WHERE n.tid = t.tid AND nid = %d', $node->nid);
        while($row = db_fetch_array($result)){
          $key = array_search($row, $_SESSION['autotag_tids'][$node->form_build_id]);
          if($key !== FALSE){
            unset($_SESSION['autotag_tids'][$node->form_build_id][$key]);
          }
        }

Are you sure that the module should have the same behavior in the two cases?
case-update
case-insert

Best

kenorb’s picture

Priority: Major » Normal
Issue summary: View changes
alvar0hurtad0’s picture

Status: Active » Closed (outdated)

Closing this issue as seems to be outdate.

Please, re-open in case someone else needs support with it.