'Is not equal to' operator ignored on exposed, grouped filter

Created on 8 August 2019, almost 5 years ago
Updated 22 March 2024, 3 months ago

Problem/Motivation

Using 'Is not equal to' in a grouped exposed filter for a boolean field does not work as expected.

Steps to reproduce

  1. Install Drupal
  2. Create a content type with a boolean field
  3. Create a node with the boolean field checked
  4. Create a node without it checked
  5. Create a view of this node type
  6. Add an exposed, grouped filter where
    1. Grouping 1 = Label: True, Operator: Is equal to, Value: True
    2. Grouping 2 = Label, Not true, Operator: Is not equal to: True
  7. Test the exposed filter, see that the node with the field checked appears for both True and Not true

Expected result: The node without the field checked should appear for Not true

The SQL query for both filters is the same:

SELECT "node_field_data"."langcode" AS "node_field_data_langcode", "node_field_data"."nid" AS "nid"
FROM
{node_field_data} "node_field_data"
LEFT JOIN {node__field_checkbox_1} "node__field_checkbox_1" ON node_field_data.nid = node__field_checkbox_1.entity_id AND node__field_checkbox_1.deleted = '0'
WHERE ("node_field_data"."type" IN ('checkbox')) AND ("node__field_checkbox_1"."field_checkbox_1_value" = '1')
LIMIT 11 OFFSET 0

Proposed resolution

Allow boolean fields to be used with grouped filters for 'Is not true'.

Remaining tasks

  1. Write patch with tests
  2. Review

User interface changes

N/A

API changes

N/A

Data model changes

N/A

Release notes snippet

N/A

==================

Problem/Motivation

In a view, for an exposed, grouped filter, the specified operator is apparently ignored.

Steps to reproduce:

  • a clean install of 8.7.6
  • in /admin/structure/views/settings, turn on Show the SQL query (you need to tick 'Show information and statistics about the view during live preview' first, which is a bit of a UX issue in it's own right, imho)
  • then edit the Content view (views.view.content)
  • edit the Content: Published filter (labelled 'Published status')
  • change the second grouping (Unpublished) from: 'is equal to no' to: 'is not equal to yes'
  • test each value of the dropdown using the Preview, examining at the SQL query

Expected:

selecting Unpublished and pressing Filter should give a query fragment of:

WHERE (node_field_data.status != '1') AND …

Observed:

WHERE (node_field_data.status = '1') AND …

(similarly, if you set it to 'is not equal to no', you still get: node_field_data.status = '0')

Proposed resolution

Remaining tasks

  • Is this a duplicate of another bug? (I did a cursory search)
  • Establish cause.
  • Write patch.

User interface changes

none

API changes

none expected

Data model changes

none expected

Release notes snippet

🐛 Bug report
Status

Fixed

Version

9.5

Component
Views 

Last updated about 9 hours ago

Created by

🇬🇧United Kingdom wturrell

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024