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.
| Comment | File | Size | Author |
|---|---|---|---|
| drupal-7-ensure-unduplicated-join-statements.patch | 456 bytes | eMPee584 | |
| drupal-6-ensure-unduplicated-join-statements.patch | 434 bytes | eMPee584 |
Comments
Comment #1
Crell commentedThis is only an issue for D6. For D7, we're killing db_rewrite_sql(): #299176: Replace db_rewrite_sql() with hook_query_alter().
Comment #2
eMPee584 commentedthis really doesn't need a test to get committed, does it??
Comment #3
eMPee584 commentedGuess this is simple enough to not need a test as it just removes a duplicate SQL JOIN condition. RTBC.
Comment #4
gábor hojtsyWould 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.
Comment #5
eMPee584 commentedJOIN statements *need* to be unique. They are created from that array. Can the validity of this fix be any more obvious?
Well it makes that query fail, producting empty views. It happened to my frontpage view after enabling webform_report... not critical?
Comment #6
eMPee584 commentedAs 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...
Comment #7
dave reidIs this a duplicate of #284392: db_rewrite_sql causing issues with DISTINCT?
Comment #8
eMPee584 commentedI don't think so.
Comment #9
thedavidmeister commentedD7 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.