I've just installed the image module, and when I use it with adminstrator priveleges, everything works fine. However, when I use it as a regular user, function db_rewrite_sql is invoked, and in turn invokes node_db_rewrite_sql in a way that seems to damage the query, so that image galleries cannot be used. In particular, when i try to use the image module as a non-administrator, so that db_rewrite_sql modifies the query to include access control, my site is throwing an sql error:

user error: Unknown column 'n.nid' in 'on clause'
query: SELECT t.tid, COUNT(DISTINCT(n.nid)) AS c FROM term_node t INNER JOIN node_access na ON na.nid = n.nid , node n WHERE  (na.grant_view = 1 AND CONCAT(na.realm, na.gid) IN ('all0','term_access4','term_access6','term_access7')) AND  t.nid = n.nid AND n.status = 1 AND n.type = 'image' GROUP BY t.tid in /var/www/drupal46/includes/database.mysql.inc on line 66.

The erroneous sql query above is the result of a rewrite of the sql query from the image_page function.

CommentFileSizeAuthor
#3 taxonomy_25.patch1.04 KBkilles@www.drop.org

Comments

karger’s picture

Project: Image » Drupal core
Version: 4.6.x-1.x-dev » 4.6.5
Component: image.module » node.module

I've confirmed that this really is caused by node_db_rewrite_sql. Even the following innocuous sql query:

select t.tid FROM {term_node} t INNER JOIN {node} n ON t.nid=n.nid

gets rewritten into invalid sql:

select t.tid FROM term_node t  INNER JOIN node_access na ON na.nid = n.nid INNER JOIN node n ON t.nid=n.nid WHERE (na.grant_view = 1 AND CONCAT(na.realm, na.gid) IN ('all0','term_access4','term_access6','term_access7'))

because the 'join' regular expression in node_db_rewrite_sql terminates at the first capital letter following FROM---namely the I of INNER JOIN that brings in the '{node} n' definition that would make n.nid parseable.

karger’s picture

Priority: Critical » Normal
killes@www.drop.org’s picture

Version: 4.6.5 » x.y.z
Component: node.module » taxonomy.module
Status: Active » Needs review
StatusFileSize
new1.04 KB

Here's a patch.

codepoet’s picture

Status: Needs review » Needs work

I applied the patch and my site is still generating the errors:

Unknown column 'n.nid' in 'on clause' query: SELECT DISTINCT(n.nid), n.title, u.uid, u.name FROM node_counter s INNER JOIN node_access na ON na.nid = n.nid INNER JOIN node n ON s.nid = n.nid INNER JOIN users u ON n.uid = u.uid WHERE (na.grant_view = 1 AND CONCAT(na.realm, na.gid) IN ('all0','term_access1')) AND s.totalcount <> '0' AND n.status = 1 ORDER BY s.totalcount DESC LIMIT 0, 5 in /home/ahknight/www/drupal-sites/includes/database.mysql.inc on line 66.

In this case, it's a call from statistics.module being rewritten to include taxonomy_access tables (I presume from node_access via taxonomy module).

Tried 4.6.5 with patched taxonomy module from taxonomy_access on PHP 5/MySQL 5.1 as well as the stock 4.6.5 patched with just the above.

However, turning off taxonomy_access seems to fix this for me.

codepoet’s picture

I should clarify: turning off taxonomy_access in the taxonomy_access module resolved it, not unloading the module.

chx’s picture

Status: Needs work » Closed (duplicate)