I got this error when filtering content by more than 1 category on admin/node page:

user error: Not unique table/alias: 'tn'
query: SELECT n.*, u.name, u.uid FROM node n INNER JOIN term_node tn ON n.nid = tn.nid INNER JOIN term_node tn ON n.nid = tn.nid INNER JOIN users u ON n.uid = u.uid WHERE tn.tid = 1 AND tn.tid = 1 ORDER BY n.changed DESC LIMIT 0, 50 in /var/www/icon/includes/database.mysql.inc on line 66.

I think the error is in the join option for category filter. Its value is "INNER JOIN {term_node} tn ON n.nid = tn.nid".

Comments

Jhef.Vicedo’s picture

My temporary solution for this is replacing the "tn." in:

foreach ($session as $filter) {

    list($key, $value) = $filter;

    if ($key == 'status') {

      // Note: no exploit hole as $value has already been checked

      list($key, $value) = explode('-', $value, 2);

      $where[] = 'n.'. $key .' = %d';

    }

    else {

    	if ($key == 'category') {    	  

    	  $where[] = str_replace('tn.', 'tn.'$cat_index, $filters[$key]['where']);    	  

    	} 

    	else {

        $where[] = $filters[$key]['where'];

    	}

    }

    $args[] = $value;

    if ($key == 'category') {

      $join .= str_replace('tn.', 'tn.'$cat_index, $filters[$key]['join']);

      $cat_index++;

    }

    else {

      $join .= $filters[$key]['join'];

    }    

  }
Jhef.Vicedo’s picture

This is on node_admin_nodes() function (building the query). Sorry I forgot to mention this above.

beginner’s picture

Priority: Critical » Normal

Hello, I cannot reproduce on 4.7.
Can you still reproduce this on the latest 4.6.8?
What are the exact steps to reproduce the error?
What do you mean by " filtering content by more than 1 category"?

tmckeown’s picture

I can verify this bug on Drupal 4.6.5. I am currrently working on a patch

magico’s picture

@tmckeown: anything new?

magico’s picture

Version: 4.6.6 » 4.6.10
Status: Active » Fixed
Anonymous’s picture

Status: Fixed » Closed (fixed)