When I submit an article with freetagging, it will show the warning message.
If the taxonomy wrapper is uninstall, the warning message will disappear.

php 5.0
drupal 5.2-dev

user warning: Unknown column 'Object' in 'field list' query: INSERT INTO term_node (nid, tid) VALUES (68, Object) in /var/www/includes/database.mysqli.inc on line 151.

Comments

2houseplague’s picture

sjh-1’s picture

The symptoms are bit different to what I'm seeing, but from the code it looks a product of exactly the issue I've been looking at. It has to do with the taxonomy field of the node structure being initialised directly from the value in the category field. The problem is that tid then doesn't exist, and the insertion code that is lifted directly from the taxonomy module expects it to be there if $node->taxonomy is an object.

My patch for it is at http://drupal.org/node/87669#comment-225000

dingbats’s picture

Title: A warning about taxonomy wrapper module » Taxonomy wrapper causes mysql errors when saving nodes
Version: 5.x-1.x-dev » master

I looked inside the taxonomy wrapper module. At the bottom of the taxonomy_node_save function, there is a foreach loop that iterates over $terms:

function taxonomy_node_save($nid, $terms, $node=NULL) {
// ...
foreach ($terms as $key => $term) {
        if ($key != 'tags' && $key != 'legacy') {
          if (is_array($term)) {
            foreach ($term as $tid) {
              if (!empty($tid)) {
                db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $tid);
              }
            }
          }
          else if (isset($term->tid)) {
            db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $term->tid);
          }
          else if ($term) {
            db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $term);
          }
        }
      }

Let's examine the structure of a category object (a var_dump of $terms)

array(1) {
    [13]=>
    object(stdClass)(8) {
      ["nid"]=> string(2) "13"
      ["node_id"]=>string(2) "12"
      ["cid"]=>string(2) "13"
      ["cnid"]=> string(1) "1"
      ["description"]=> string(0) ""
      ["weight"]=> string(1) "0"
      ["depth"]=> string(1) "0"
      ["title"]=> string(15) "Example category 1"
    }
  }

Looking at the conditional statement in the taxonomy_node_save function, we see that because the object in $terms isn't an array, nor does it have an attribute 'tid', the last condition is true (i.e., the object is not null) and this is parsed:

            db_query('INSERT INTO {term_node} (nid, tid) VALUES (%d, %d)', $nid, $term);

Of course, $term is not an integer, but a category object, so it is converted to the string, 'Object' and substituted into the query. For me $term is substituted as '1', probably because of my php version. And, consequently, the mysql error I receive is:
Duplicate entry '1-12' for key 1 query: taxonomy_node_save INSERT INTO term_node (nid, tid) VALUES (12, 1) in database.mysql.inc on line 172.

I can see two solutions for this problem, however, I don't know enough about the taxonomy or category modules to decide which is more appropriate:

  1. Conform to category format. This results in a change to the code, so that instead of testing for the attribute 'tid', we test for 'cid' which corresponds to the term id in the term data table anyway. And, then we also insert the 'cid' value as the 'tid' in the term_node table.
  2. Conform to taxonomy format. This results in a change how the category is loaded, so the category object will have a new attribute 'tid', which essentially enables the category object to be used as a term object.

Please suggest any other alternatives so we can quickly patch this issue up.

inforeto’s picture

For patching to those structures see here:
http://drupal.org/node/87669

The original post don't seem a duplicate, but might be related.