I suspect only very few users have run into this obscure error.. it caused my frontpage view being empty for anonymous users (DOH!!! GAU!).. Both modr8_db_rewrite_sql and webform_report_db_rewrite_sql add the same join statement:

          $return['join'] = "LEFT JOIN {node} n ON $primary_table.nid = n.nid";

which causing the query to fail with this error:

Message
Not unique table/alias: 'n'
query: SELECT node.nid AS nid,
   node.sticky AS node_sticky,
   node.created AS node_created
 FROM node node 
  LEFT JOIN node n ON node.nid = n.nid LEFT JOIN node n ON node.nid = n.nid WHERE ((n.moderate != 1)) AND
  (n.type <> 'webform_report') AND (  (node.promote <> 0) AND (node.status <> 0) AND
  (node.language in ('en', 'en'))
   )ORDER BY node_sticky DESC, node_created DESC
 LIMIT 0, 6 in /var/www/drupal-hfopi/sites/all/modules/views/includes/view.inc on line 723.

The solution is to invoke a array_unique on the join array. Don't think this is needed for the WHERE statements too.. patches attached, applies to D6 and HEAD.

Comments

Crell’s picture

Version: 7.x-dev » 6.x-dev

This is only an issue for D6. For D7, we're killing db_rewrite_sql(): #299176: Replace db_rewrite_sql() with hook_query_alter().

eMPee584’s picture

this really doesn't need a test to get committed, does it??

eMPee584’s picture

Assigned: Unassigned » eMPee584
Status: Needs review » Reviewed & tested by the community

Guess this is simple enough to not need a test as it just removes a duplicate SQL JOIN condition. RTBC.

gábor hojtsy’s picture

Priority: Critical » Normal
Status: Reviewed & tested by the community » Needs review

Would be good to have an independent eye on it. Also, you make the point that it is an obscure and uncommon error, but still say critical. I am not sure that stands.

eMPee584’s picture

Would be good to have an independent eye on it.

JOIN statements *need* to be unique. They are created from that array. Can the validity of this fix be any more obvious?

Also, you make the point that it is an obscure and uncommon error, but still say critical. I am not sure that stands.

Well it makes that query fail, producting empty views. It happened to my frontpage view after enabling webform_report... not critical?

eMPee584’s picture

As of now, this fix hasn't been committed. Can someone have a look at it, should be really obvious that the array_join collapses duplicate join clauses. Patch from the OP still applies, as _db_rewrite_sql is still in D7 it applies there, too...

dave reid’s picture

eMPee584’s picture

I don't think so.

thedavidmeister’s picture

Status: Needs review » Needs work

Patch from the OP still applies, as _db_rewrite_sql is still in D7 it applies there, too...

D7 does not have _db_rewrite_sql().

Patch for D6 does not seem to apply, it's probably the old style pre-git. The patch itself looks ok (I haven't manually tested it), although it wouldn't work for upper/lower case duplicate joins. Not sure if that's an issue.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.