When using an exposed filter on a term, that has a relation to a configured vocabulary. The views query is broken.

I filter on term id 4:

As admin, following query is constructed:

SELECT DISTINCT node.title AS node_title, node.nid AS nid, node.type AS node_type, users_node.name AS users_node_name, users_node.uid AS users_node_uid, node.changed AS node_changed, 'node' AS field_data_field_article_category_node_entity_type FROM node node LEFT JOIN (SELECT td.*, tn.nid AS nid FROM taxonomy_term_data td LEFT JOIN taxonomy_vocabulary tv ON td.vid = tv.vid LEFT JOIN taxonomy_index tn ON tn.tid = td.tid WHERE (tv.machine_name IN (<strong>'category'</strong>)) ) taxonomy_term_data_node ON node.nid = taxonomy_term_data_node.nid LEFT JOIN users users_node ON node.uid = users_node.uid WHERE (( (taxonomy_term_data_node.tid = '4') )) ORDER BY node_changed DESC LIMIT 20 OFFSET 0

When doïng the same as non-admin, following thing occures:

SELECT DISTINCT node.title AS node_title, node.nid AS nid, node.type AS node_type, users_node.name AS users_node_name, users_node.uid AS users_node_uid, node.changed AS node_changed, 'node' AS field_data_field_article_category_node_entity_type FROM node node LEFT JOIN (SELECT td.*, tn.nid AS nid FROM taxonomy_term_data td LEFT JOIN taxonomy_vocabulary tv ON td.vid = tv.vid LEFT JOIN taxonomy_index tn ON tn.tid = td.tid WHERE (tv.machine_name IN (<strong>'4'</strong>)) ) taxonomy_term_data_node ON node.nid = taxonomy_term_data_node.nid LEFT JOIN users users_node ON node.uid = users_node.uid WHERE (( (taxonomy_term_data_node.tid = '4') )) ORDER BY node_changed DESC LIMIT 20 OFFSET 0
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

nils.destoop’s picture

Included is the patch. Somehow, assigning variables in the foreach messes up the query. (PHP 5.2.13)

nils.destoop’s picture

little fix in patch

nils.destoop’s picture

Completely ignore my patches. :p

nils.destoop’s picture

Now the correct patch. Previous patches would fail if you use multiple node tables.
Problem occures when one of the tables is a subquery.

nils.destoop’s picture

In patch 2 things should not be deleted.

- $search = FALSE;
- $node = FALSE;

nils.destoop’s picture

Status: Active » Needs review
Alan D.’s picture

Which version of Drupal 7 core are you using?

Alan D.’s picture

Status: Needs review » Postponed (maintainer needs more info)

I have tried to replicate this with the supplied information, but I could not.

The patch bypasses the apparent issue, but maybe it should be adapted to handle the change rather than ignoring it.

At minimal, I need steps like:

Create a content type and add a Term reference to a single taxonomy
Create a view of this type and assign an exposed widget that filters on this term. (I also added a Search keyword exposed form too.)
Save and search using a term from this vocabulary

Which is what I did and I had no issues

Alan D.’s picture

And looking at the query, this looks like it is a bug from the core Drupal DB system that was fixed in Drupal 7.8....

Alan D.’s picture

Status: Postponed (maintainer needs more info) » Closed (duplicate)

Marking duplicate of the core bug that was fixed years ago, whatever that was again. There are still a couple of core Drupal access bugs still unresolved too.