I have a view that I am using to generate two displays that are shown on a page with quicktabs. The views have a primary (non-exposed) filter for a completion state, which is a Text List field on the Node:

  • Planned
  • In Progress
  • Delayed
  • Complete
  • Canceled

The View Display is a FooTable (this is unrelated). On one View Display, I set the primary (non-exposed) filter to ONE OF and limit the select list options to 'Planned', 'In Progress' and 'Delayed'. I then add an exposed filter to allow users to further refine the list to one of these three options, so there are two filters for the same field.

I have found that in order for the above to work properly, the non-exposed filter (primary) must be ordered ABOVE the exposed filter.

But things get funny with my second View Display, in which I have a primary (non-exposed) filter to ONE OF 'Complete', 'Canceled' combined with a secondary exposed filter for these two list items. When selecting 'Complete' in the exposed filter, the SQL output shows the following in the query:

LEFT JOIN {field_data_field_permit_status} field_data_field_permit_status2 ON node.nid = field_data_field_permit_status2.entity_id AND field_data_field_permit_status2.field_permit_status_value != 'Complete'

Note that the query is now looking for anything that does NOT have the term 'Complete', which is the opposite of what we want. This is a bug.

A workaround is to change the non-exposed primary filter to select the initial terms through an inverse (IS NOT ONE OF 'Planned', 'In Progress', 'Delayed'). This will then work with a secondary filter of IS ONE OF, however it appears that two filters on a select list IS ONE OF does not work.

Comments

brooke_heaton created an issue. See original summary.

brooke_heaton’s picture

Issue summary: View changes
matthiasm11’s picture

I can confirm the issue. Quickly investigated the code, but could not find where the LEFT JOIN was added.

I did found this:
The primary (non-exposed) filter adds a WHERE clausule to the query, this is normal behaviour. It will look something like this:

WHERE ...
AND (field_data_field_categorie.field_categorie_tid IN  ('8', '33', '26', '27', '28', '32', '29', '30', '31', '111'))

The secondary (exposed) filter, will not add any additional JOINS when it was not used, this is also normal behaviour.
When the secondary (exposed) filter is used, for example the first item is checked (term id 8 in my example), all works fine: an additional where clausule will be added. So we get a where clausule from the primary (non-exposed) filter, and a where clausule from the secondary (exposed) filter. It will look something like this:

WHERE ...
AND (field_data_field_categorie.field_categorie_tid IN  ('8', '33', '26', '27', '28', '32', '29', '30', '31', '111'))
AND (field_data_field_categorie2.field_categorie_tid = '8')

But when the last item (term id 111 in my example) is checked, the LEFT JOIN query with impossible filter is added. The query will look something like this:

LEFT JOIN {field_data_field_categorie} field_data_field_categorie2 ON node.nid = field_data_field_categorie2.entity_id
AND field_data_field_categorie2.field_categorie_tid != '111'
WHERE ...
AND (field_data_field_categorie.field_categorie_tid IN  ('8', '33', '26', '27', '28', '32', '29', '30', '31', '111'))
AND (field_data_field_categorie2.field_categorie_tid = '111')

I retested this a couple of times in different displays with different term id's and can confirm the issue only occurs with the last item of the primary (non-exposed) filter in the WHERE clausule.

Temporary using the described work around: IS NOT ONE OFF in the primary (non-exposed) filter.

mrdalesmith’s picture

I'm having this issue too, with the exact same impossible JOIN being added to the SQL query. I've added a link to 1309578 as the only reason I need two filters (one exposed, one not) on the same view is to limit the initial results when "Limit to selected items" in the exposed filter doesn't already do this.

mehul.shah’s picture

Yes, this is applicable to the latest version of the Drupal - i.e. 8.7

I am working on taxonomy term reference field "status" attached to a node, I have created a view and applied 2 filters on this field. Out of which one is Non - exposed and other is exposed.

The view works properly when I don't use the exposed filter but as soon as I use the exposed filter it works weirdly. check out the query below for more understanding.

LEFT JOIN {node__field_status} node__field_status2 ON node_field_data.nid = node__field_status2.entity_id AND INNER JOIN {node__field_status} node__field_status ON node_field_data.nid = node__field_status.entity_id AND node__field_status.deleted = '0'
LEFT JOIN {node__field_status} node__field_status2 ON node_field_data.nid = node__field_status2.entity_id AND node__field_status2.field_status_target_id != '5'

The first join is for the Non-exposed filter and the second join is for the exposed filter if you look at the condition of the second join it indicates node__field_status2.field_status_target_id != '5', which is exactly opposite of what i am trying to do.

damienmckenna’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 7.x-3.11 » 8.8.x-dev
Component: exposed filters » views.module

FYI in Drupal 8 the Views module was added to core. As a result, all issues related to Views for Drupal 8 should be added to the Drupal core issue queue. Hopefully someone will be able to help you there.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

krowrof’s picture

Still occurs in 8.8 - but a work around seems to be to enable "Reduce duplicates" on the exposed filter.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

matroskeen’s picture

Issue tags: +Bug Smash Initiative

It occurred to me on 8.9.x project and still reproducible on the latest 9.2.x.

The problem seems the following:
1) During the processing of the first filter, the active value (which is a value selected in the exposed filter) is saved in this line;
2) For the second filter, this value is retrieved and added as a condition in this line, because in the $this->handler->view->many_to_one_tables this field exlready exists;

I'm not familiar with views enough, so I'm not sure what the solution should be.

Steps to reproduce are pretty easy:
1) Install Drupal with Standard profile;
2) Open "People" view (admin/structure/views/view/user_admin_people);
3) Add one more filter for "Role" (should be not exposed) and limit displayed roles;
4) Select any role in the exposed filter "Role";
5) You should see a similar join:
LEFT JOIN {user__roles} "user__roles2" ON users_field_data.uid = user__roles2.entity_id AND user__roles2.roles_target_id != 'administrator'

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

noelia_11’s picture

Workaround at #8 working here!

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

nnevill’s picture

But still occurs in 9.3.2.

But good news – workaround from #8 works but it's important to place non-exposed filter before exposed.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

frankdesign’s picture

In case someone arrives on this issue page and they are using Grouped Filters, the "Reduce duplicates" options is not available in the UI on Grouped Filters. So as a workaround, you need to revert to a Single Filter, put a tick in "Reduce duplicates" and then recreate the Grouped Filter.

javier_rey’s picture

I can confirm that this still appears at 10.4.2.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.