In 1.36.2.1, a query on line 367 was wrapped with db_rewrite_sql. For some reason on our site this query then broke for users without admin rights - it kept working for users with admin rights though.
This was the error message:
user error: Unknown column 'n.nid' in 'on clause'
query: SELECT n.tid FROM term_hierarchy t INNER JOIN node_access na ON na.nid = n.nid , term_data n WHERE (na.grant_view = 1 AND CONCAT(na.realm, na.gid) IN ('all0','node_privacy_byrole_role2','node_privacy_byrole_user2')) AND t.tid = n.tid AND n.vid = 3 AND t.parent = 0 ORDER BY n.weight, n.name in /includes/database.mysql.inc on line 66.
Not being much of a SQL expert, I couldn't tell what the exact problem was.
After some looking at the db_rewrite_sql docs, I suspected that defaulting to the node table and nid fields probably wasn't what was required.
I changed line 367 from (patch attached):
$result = db_query(db_rewrite_sql("SELECT n.tid FROM {term_hierarchy} t, {term_data} n WHERE t.tid = n.tid AND n.vid = %d AND t.parent = 0 ORDER BY n.weight, n.name"), $vid);
to:
$result = db_query(db_rewrite_sql("SELECT td.tid FROM {term_hierarchy} th, {term_data} td WHERE th.tid = td.tid AND td.vid = %d AND th.parent = 0 ORDER BY td.weight, td.name", "term_data", "tid"), $vid);
and it seems to work again. I added the "term_data" and "tid" parameters to db_rewrite_sql and changed the table aliases to something more intuitive.
I'm not sure how correct it is though, or why it worked for admins users.
| Comment | File | Size | Author |
|---|---|---|---|
| taxonomy_context.module.diff | 698 bytes | styro |
Comments
Comment #1
styro commentedCorrecting status.
Comment #2
nedjoI had a quick look and it looks fine (though I haven't tested it). Please commit if you have CVS write access; otherwise I'll do when I get a chance.
Nedjo
Comment #3
styro commentedThanks - no, I don't have CVS access :)
Comment #4
nedjoThis is now fixed.
Comment #5
(not verified) commented