Using Views Bulk Operations, I was assigning nodes (in bulk) to various terms. I was getting a bunch of errors from term_node_count_count_nodes() as VBO was passing BLANK terms.

Short story ... instead of producing an erroneous list like (45,,113) and chucking an error, using my "workaround" you can guard against people passing blank $tids into the term_node_count_count_nodes() function.

File: term_count.module
Line 103,104:

$tids_list = implode(',', $terms);
$tids_list = rtrim($tids_list, ',');

should be changed to:

$tids_cache=array();
foreach($terms as $tid){if($tid) $tids_cache[]=$tid;}
$tids_list = implode(',',$tids_cache);

Not really a bug with the module ... just a bit of defensive coding that fixes an error I was having.

One day I'll learn how to roll a patch. Hope I made sense.

CommentFileSizeAuthor
#1 term_node_count-560172-1.patch542 bytesagileware

Comments

agileware’s picture

Title: Invalid SQL generated ... and workaround. » Invalid SQL generated (sql error in term_node_count.module on line 107)
Status: Active » Needs review
StatusFileSize
new542 bytes

Here is a patch that should fix this.

I would classify it as a bug because it is a problem with the code that causes an error.

An example of this error for people who are trying to find a solution for this problem is:

user warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1504,1265,104) AND n.status = 1 GROUP BY tid' at line 1 query: SELECT tid, COUNT(tid) AS count FROM term_node tn INNER JOIN node n ON tn.vid = n.vid WHERE tid IN (1,16,6,5,,1504,1265,104) AND n.status = 1 GROUP BY tid in /var/www/vhosts/mysite/sites/all/modules/vanilla/term_node_count/term_node_count.module on line 107.

alexku’s picture

I think the real problem is on line 168: if ($key != 'tags')

From the PHP manual: If you compare a number with a string or the comparison involves numerical strings, then each string is converted to a number and the comparison performed numerically.

try: var_dump(0 != 'tags'); and you will get 0 in the result

So the solution would be: if ($key !== 'tags')

Spent few hours trying to understand what is wrong with my code before noticing this little bug :)

Pls’s picture

I might make a patch from alexku comments this week. Let's test it before patch. Thanks.

YK85’s picture

subscribing