D7.12
forum.module around l. 779 raises a PDO Exception.
There seem to be two issues related to the sql inserted by
$query ...
->addTag('node_access') on l.778
First this makes the reference to status ambiguous in l. 776
I changed that to
->condition('n.status', 1)
Which helped but then I got the error below
(which goes away if the addTag('node_access') line is removed).
I couldn't figure out how to clean that up.
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'node.tid' in 'on clause': SELECT f.tid AS tid, COUNT(n.nid) AS topic_count, SUM(ncs.comment_count) AS comment_count FROM {node} n INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {node} node ON f.tid = node.tid WHERE (n.status = :db_condition_placeholder_0) AND (n.language IN (:db_condition_placeholder_1, :db_condition_placeholder_2)) GROUP BY tid; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => en [:db_condition_placeholder_2] => und ) in forum_forum_load() (line 779 of /home/dharmaga/public_html/dev.dharmagarasia.info/modules/forum/forum.module).
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 1430386-unknown-tid-2.patch | 466 bytes | larowlan |
| #4 | 1430386-unknown-tid.patch | 542 bytes | larowlan |
Comments
Comment #1
fergusong commentedComment #2
larowlanWhat node access modules do you have enabled?
Comment #3
larowlanComment #4
larowlanComment #6
larowlanComment #7
fergusong commentedThanks for the response,
The access control modules I have enabled are ACL and Content Access.
I also have most of the i18n modules enabled.
I updated my forum.module file per the patch, but it didn't solve the problem.
If I comment out the addTag('node_access') line it works fine either way.
The code I've got from l. l775
if (count($_forums)) {
$query = db_select('node', 'n');
$query->join('node_comment_statistics', 'ncs', 'n.nid = ncs.nid');
$query->join('forum', 'f', 'n.vid = f.vid');
$query->addExpression('COUNT(n.nid)', 'topic_count');
$query->addExpression('SUM(ncs.comment_count)', 'comment_count');
$counts = $query
->fields('f', array('tid'))
->condition('n.status', 1) // gjf added n. prefix
->groupBy('f.tid') // gjf: added f. prefix
->addTag('node_access') // gjf: wondering
->execute()
->fetchAllAssoc('tid');
}
The report
PDOException: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'node.tid' in 'on clause': SELECT f.tid AS tid, COUNT(n.nid) AS topic_count, SUM(ncs.comment_count) AS comment_count FROM {node} n INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {node} node ON f.tid = node.tid WHERE (n.status = :db_condition_placeholder_0) AND (n.language IN (:db_condition_placeholder_1, :db_condition_placeholder_2)) GROUP BY f.tid; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => en [:db_condition_placeholder_2] => und ) in forum_forum_load() (line 779 of /home/dharmaga/public_html/dev.dharmagarasia.info/modules/forum/forum.module).
Comment #8
oriol_e9gEdited by mistake in the comment.
Comment #9
oriol_e9gComment #10
larowlanThe add tag node access tells your node access modules to rewrite the query and invoke their access limitations. Without the add tag, you won't get expected access controls. I suspect the issue is with the rewriting as the join on tid isn't done by core. Please disable acl and content access and report back.
Comment #11
trigdog commentedI am also having this problem. I have similar modules enabled (Content Access, ACL, i18n) on D7.12 (Didn't have this issues on D7.10). Will try disabling different modules and report back. Saw this over in the Internationalization issues and thought they might be related - http://drupal.org/node/1429962
Comment #12
fergusong commentedI disabled those modules but the problem continued.
The problematic sql seems to be
INNER JOIN {node} node ON f.tid = node.tid
and that sees to be created in the 'node_access' processing...
The problem occurs for my admin account but not for other roles.
More specifically, looking at _node_query_node_access_alter() in node.module
If I get to l.3170 (i.e. don't have 'bypass node access') then the
bug occurs. That seems odd, why is it doing anything
if it doesn't get there? But it is what I'm seeing.
Comment #13
larowlansee also #1431452: Tests for 'status' in where clause is ambiguous for the fix to the status issue
Comment #14
larowlancan you add this to the end of node_query_node_access_alter function
and paste the output here
Comment #15
fergusong commentedIn a failure case I see
SELECT f.tid AS tid, COUNT(n.nid) AS topic_count, SUM(ncs.comment_count) AS comment_count FROM {node} n INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {node} node ON f.tid = node.tid WHERE (n.status = :db_condition_placeholder_0) AND (n.language IN (:db_condition_placeholder_1, :db_condition_placeholder_2)) GROUP BY tid
Also: I can't replicate the odd result with varying Roles, I must have
screwed up the test cases somewhere. Apologies for that false track.
Comment #16
superthin commentedDrupal 7.12 when visiting my site http://mysite.com/forum
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'status' in where clause is ambiguous: SELECT f.tid AS tid, COUNT(n.nid) AS topic_count, SUM(ncs.comment_count) AS comment_count FROM {node} n INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {node} node ON f.tid = node.tid WHERE (status = :db_condition_placeholder_0) AND (n.language IN (:db_condition_placeholder_1, :db_condition_placeholder_2)) GROUP BY tid; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => vi [:db_condition_placeholder_2] => und ) trong advanced_forum_forum_load() (dòng 142 của /var/www/clients/client1/web29/web/sites/all/modules/advanced_forum/includes/core-overrides.inc).
Comment #17
sbasurto commentedDONT USE THIS see #18
I just did it for testing prouposes, this is not a solution to the problem also see #23
I receive the same error
PDOException: SQLSTATE[42703]: Undefined column: 7 ERROR: column node.tid does not exist LINE 6: INNER JOIN node node ON f.tid = node.tid ^: SELECT f.tid AS tid, COUNT(n.nid) AS topic_count, SUM(ncs.comment_count) AS comment_count FROM {node} n INNER JOIN {node_comment_statistics} ncs ON n.nid = ncs.nid INNER JOIN {forum} f ON n.vid = f.vid INNER JOIN {node} node ON f.tid = node.tid WHERE (node.status = :db_condition_placeholder_0) AND (n.language IN (:db_condition_placeholder_1, :db_condition_placeholder_2)) GROUP BY f.tid; Array ( [:db_condition_placeholder_0] => 1 [:db_condition_placeholder_1] => es [:db_condition_placeholder_2] => und ) en forum_forum_load() (line 779 of modules/forum/forum.module).
and surpas it doing the following:
and in the file forum.module change the lines:
I am sure this is not the right way, because it "fix" forum but breaks all the site, the problem is that the JOIN is being doing with "tid" in the "forum module", but in "node" table this column does not exist.
Regards,
Comment #18
bak commentedDON'T DO THE "FIX":
alter table node rename column tnid to tid;The node.tnid and forum.tid columns have a different purpose.
I think the problem is that one of function/module/code inside the Drupal 7.12 (I dont know yet which one and why) is adding automatically :
INNER JOIN {node} node ON f.tid = node.tidto the select clause if we're trying to fetch the f.tid field from the inner joined table (forum).
Comment #19
larowlanJust to reiterate DO NOT USE THE FIX mentioned at #17.
tnid is for the node translation set
tid is for taxonomy terms
this is not the correct fix, the issue with with node_access rewriting the query and adding in the node table again (it's already in the query) as per comments at #18.
Comment #20
fergusong commentedI agree with bak's comment #18.
A little more background. I am trying to learn i18n, and following the tutorial at http://drupal.org/node/1268692
I installed a fairly long list of modules.
I repeated the step earlier today on a second
site and our problem recurred only after install/enabling them. That may narrow things down
a bit. And it may allow others to reproduce the bug.
And I should experiment with selectively disabling these modules to find the culprit, but that
probably won't happen tonight.
Comment #21
larowlanCan you grep your code base for functions implementing hook_query_node_access_alter other than node_query_node_access_alter.
The default node_query_node_access_alter would not alter the query as shown at #15 - it would be joining against the node_access table so I am hoping it's another contrib module that's implementing hook_query_node_access_alter and struggling.
Comment #22
fergusong commentedGrep, why didn't I think of that, results in
i18n/i18n_select/i18n_select.module: * Implementation of hook_query_node_access_alter().
views/plugins/views_plugin_query_default.inc: // If not, then hook_query_node_access_alter() may munge the count by
The interesting line is the i18n_select.module. AND if I disable i18n_select the error does not
occur, if I enable the module the error returns.
I'll post this as an issue for that module.
There is an old but somewhat related http://drupal.org/node/1065938
And a new post which seems to be reporting the same underlying issue: http://drupal.org/node/1437932
I have added a comment to that post referring to this one and summarizing what we've learned so far.
Comment #23
bak commentedfergusong is right. The problem is in the i18n_select.module.
Anybody interested should follow: http://drupal.org/node/1437932
Comment #24
larowlanYeeha, we've traced it.
Can everyone affected by this issue confirm they have i18n_select installed?
Marking this as fixed - bot will close it in a couple of weeks - if you aren't using i18n_select then please reopen.