Multilingual select 7.x-1.4 module is not working with Drupal forum (7.12).

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] => en [:db_condition_placeholder_2] => und ) in 
forum_forum_load()
 (line 
779
 of 
C:\xampp\htdocs\drupal\modules\forum\forum.module
).

Related - http://drupal.org/node/1309142#comment-5592678 from #8 to #13.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kerios83’s picture

Issue summary: View changes

edit

pwiniacki’s picture

I can confirm this. I also have this problem.

fergusong’s picture

This was also reported as an issue against the core forum module at
http://drupal.org/node/1430386
But further research traced it to i18n_select.
In summary:
The ambiguous status error is a bit of a distraction,
the underlying problem is the
INNER JOIN {node} node ON f.tid = node.tid
The node table has no tid column.

And, as far I as can tell, the join doesn't serve any purpose.
My guess is the place to look is
i18n_select_query_node_access_alter(QueryAlterableInterface $query)
in i18n_select.module on l.137

Gordon

fergusong’s picture

In i18n_select_check_table($query, $table_name, $field_name)

The logic is adding a join to the query on l.210 and that is related to the
problem. If I comment that line out (not recommended except to
make this point) the PDO exception does not occur. And vis versa.

bak’s picture

I think the problem occurs because the code inside i18n_select_check_table($query, $table_name, $field_name):


  // If node table doesn't exist, look for the nid column, join with node
  // and then return the alias of that.
  foreach ($query->getFields() as $field) {
    if ($field['field'] == $field_name) {
      return $query->join('node', 'node', $field['table'] . '.' . $field_name . ' = %alias.' . $field['field']);
    }
  }

assumes that the node table has a column/field $field_name but it is not always true: i.e. if we use complex query like in the forum.module:


    $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)
      ->groupBy('f.tid')
      ->addTag('node_access')
      ->execute()
      ->fetchAllAssoc('f.tid');

the fields are from the iner joined table forum, not from the node table. The code inside the i18n_select_check_table($query, $table_name, $field_name) function should be fixed.

SDC’s picture

Subscribing. I get the exact same error on any Forum page when Multilingual Select module is turned on and it disappears when I turn it off.

Zarevac’s picture

Same here, after applying the fix in the forum module topic the problem persists.

webflo’s picture

fergusong’s picture

I can confirm #7. I backed out that patch and the PDO exception does not occur.

Zarevac’s picture

Well, I now get this:

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 780 of /modules/forum/forum.module).

clemens.tolboom’s picture

clemens.tolboom’s picture

Step to reproduce through drush on a git checkout of drupal core

git checkout 7.12
drush --yes site-install
drush --yes dl i18n devel variable
drush --yes en i18n devel_generate i18n_select forum
drush genc --kill --types=forum 20 4
drush @drupal.d7 uli

Now visit http://drupal.d7/forum

Modules used:

drush pml --status=enabled --no-core
 Package                              Name                               Type    Version 
 Development                          Devel (devel)                      Module          
 Development                          Devel generate (devel_generate)    Module          
 Multilingual - Internationalization  Internationalization (i18n)        Module  7.x-1.4 
 Multilingual - Internationalization  Multilingual select (i18n_select)  Module  7.x-1.4 
 Other                                Variable (variable)                Module  7.x-1.1 
Zarevac’s picture

Sorry, my bad. Re-tracting my steps again to see if I missed anything. Have all fixes been applied to the dev version?

webflo’s picture

Confirmed the regression. Commit 07f6d61 is bad.

Zarevac’s picture

I concur.

agoradesign’s picture

I absolutely agree with webflo. When I remove these lines, I don't get an exception anymore...

Zarevac’s picture

Same here, tested it on another site and removing the lines also remove the exception.

clemens.tolboom’s picture

webflo’s picture

Status: Active » Needs review
FileSize
2.96 KB
Jose Reyero’s picture

Status: Needs review » Needs work

Last patch looks like some improvement (specially for the new tests), though I have some concerns about the i18n_select_query_node_access_alter() function, it may need some refactoring.

- The two if statements check for same conditions more than once.
- I suspect i18n_select_check_table() may be joining in the node table sometimes when not needed, if i18n_select_check_query() returns false on the first 'if'
- The function i18n_select_check_table() doesn't look very good to me anymore, maybe we should split it in two and not adding weird conditions.

So my concerns are not about the patch itself, which I guess just fixes the issue, but about how the logic in the query rewritting looks, which is not very good.

So you can commit it as a first step, also so people can download some (dev) version that temporarily fixes the bug, but this definitely needs some more refactoring...

kerios83’s picture

Very nice work guys! Lets polish this a little and fix it once and forever.

clemens.tolboom’s picture

I'm still puzzled why forum.module was in err. Patching it (by adding table aliasses) made me step a little forward. This looks like a fix for #9 but I'm not sure. Should we file a patch for forum.module?

diff --git a/modules/forum/forum.module b/modules/forum/forum.module
index f538216..4969809 100644
--- a/modules/forum/forum.module
+++ b/modules/forum/forum.module
@@ -773,11 +773,11 @@ function forum_forum_load($tid = NULL) {
     $query->addExpression('SUM(ncs.comment_count)', 'comment_count');
     $counts = $query
       ->fields('f', array('tid'))
-      ->condition('status', 1)
-      ->groupBy('tid')
+      ->condition('n.status', 1)
+      ->groupBy('f.tid')
       ->addTag('node_access')
       ->execute()
-      ->fetchAllAssoc('tid');
+      ->fetchAllAssoc('f.tid');
   }
 
   foreach ($_forums as $forum) {
gwynnebaer’s picture

Patch worked for me as well as is. Not sure if there are other implications.

mobonobomo’s picture

I got nipped by this too, very confusing. A very easy workaround is to go the the Multilingual Select settings at admin/config/regional/i18n/select and then add the path forum to the excluded pages "Enable for specific pages > All pages except those listed"

kerios83’s picture

@mobonobomo this help me a lot, thx.

Jose Reyero’s picture

Status: Needs work » Needs review
FileSize
10.5 KB

This one builds on webflo's patch (#18) but it is a bigger api rewrite, which also simplifies some parts:

- Properly check queries before adding any table or condition.
- Before joining any table, check all the fields have a proper table alias. Fix if possible, skip the query if not.
- Use schema information to find the table with the field to join new tables.

This should be much cleaner and more robust, maybe skipping some queries that were being rewritten previously (that ones with more than one table and no table alias for all conditions) but also altering some others, the kind of COUNT('nid') queries, since we use schema information to find the right table.

Please give it a try and let me know whether it works. Also more tests may be good.

webflo’s picture

Yep this looks much better. Whats this two settings "Select nodes by language" and "Select taxonomy terms by language". We should respect these settings. Right? see #1446200: Content to filter by language is setting never used.

Anonymous’s picture

The patch "i18n-clean_select_api-1437932-25.patch" repaired problem identified in http://drupal.org/node/1431452 " 'status' in where clause is ambiguous". Thanks for the hard work! D7.12.

Jose Reyero’s picture

Status: Needs review » Fixed

Cool, it seems we've got more than one issue fixed with this :-)

Committed.

@webflo,
Is there anything left about your comment in #26 ?

webflo’s picture

Nope. Everything is ok.

Bitbull’s picture

Status: Fixed » Needs review

Unfortunately, the mentioned patch failed to meet dependancies with me:

error: while searching for:
dependencies[] = i18n_node
package = Multilingual - Internationalization
core = 7.x


error: patch failed: i18n_forum/i18n_forum.info:5
error: i18n_forum/i18n_forum.info: patch does not apply
Checking patch i18n_forum/i18n_forum.test...
Checking patch i18n_select/i18n_select.module...

Working with latest version of Drupal (7.12) and i18n module (7.x-1.4) as well, and all multilingual modules enabled.
Any idea please?

Jose Reyero’s picture

Status: Needs review » Fixed

@Bitbull,
What do you mean? The patch is already *committed*.

Bitbull’s picture

... which means it's already incorporated in the i18n module? I'm still trying to figure out why the patch fails on my system ...

Anonymous’s picture

BitBull: You can manually edit the file to include the contents from the patch. It takes a while, but worked for me.

grozozo’s picture

Hi guys!
I had the issue with my multilanguage forum, I applied the patch and they work now :) Great job!

But...
(I'm on Drupal 7.12)
Now mi search form isn't working anymore :(
When I try to search something on site, all I find is:

Recoverable fatal error: Method DatabaseCondition::__toString() must return a string value en i18n_select_check_query() (line 270 de myhost/drupal/sites/all/modules/i18n/i18n_select/i18n_select.module).

I tried to pass to dev version of internationalization, and same result!

I googled my error message, and I found his solution: http://drupal.org/node/1062054, but it isn't possible to apply the solution as the internationalization code changed.

Is this related to this issue ? And am I the only one that got it?

whop’s picture

Hello, same here.
but I have this Recoverable fatal error on pages with views in content. AND only when not logged!
So i can choose, working forum or everything other with views :D

Thanks for your work.

Jose Reyero’s picture

whop’s picture

Wohoo fixed for me!
Thanks!!!!!!!

Please Jose, could you look at http://drupal.org/node/1451634
this is my last error with Drupal :D Maybe something with i18n, dont know.
Thanks

edit:
aha maybe i have it! is this patch
http://drupal.org/node/1438394
in this new dev version?

whop’s picture

So I have installed latest i18n dev feb.24, and used #34 nodereference patch.
But working only for some content types.
so i used #2 patch (module) for i18n.

Now working in all of content types, but not for all fields :D

its difficult :D

thanks for help

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

CleoQc’s picture

I downloaded everything new this Saturday, and I was getting the error. I followed what what suggested here and got it to work.

CleoQc’s picture

Oh, I followed the comment in #23, so I haven't really fixed anything, I just got a workaround that hides the problem

CleoQc’s picture

Issue summary: View changes

edit 2