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

Comments

wturrell created an issue. See original summary.

wturrell’s picture

StatusFileSize
new15.87 KB

Uploading the modified configuration of the view.

(I'm half expecting this to be a duplicate - but the only issue I turned up so far was:
#2595169: Operator 'Is not equal' of BooleanOperator doesn't work)

wturrell’s picture

Actually it appears I reported it once myself last year, but nobody commented on it: #3014579: 'Is not equal to' operator does not work as expected for boolean field in grouped exposed filter

rkostov’s picture

This patch should work.

rkostov’s picture

Status: Active » Needs review
rensingh99’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new21.18 KB
new38.07 KB
new27.34 KB

Hi,

I have edited the "Content: Published (grouped)" filter from: "is equal to no" to: "is not equal to yes" in the "Content (Content)" view. Below is a screenshot.

Before applying the patch

Screenshot output of view with status filter "Unpublished".

After applying the patch

Screenshot output of view with status filter "Unpublished".

The patch is working as designed.

Thanks,
Ren

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

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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.

Status: Reviewed & tested by the community » Needs work

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

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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.

agileadam’s picture

YES! Thank you for this patch.

Without it (on 9.1.3), my exposed grouped filters for select list fields were not working properly. Here's what was happening:

  • Using "Is one of" worked correctly.
  • Using "Is all of" with some chosen values was leading to "IN" (but didn't require ALL of them).
  • Using "Is none of" with some chosen values was leading to "IN" (instead of NOT IN).
  • Using "Is empty (null)" wasn't altering the query at all.
  • Using "Is not empty (not null)" wasn't altering the query at all.

All of those work as expected after patching.

eugene bocharov’s picture

Version: 8.9.x-dev » 9.2.x-dev
Status: Needs work » Needs review
Issue tags: +Hybrid Filters Follow-ups
StatusFileSize
new1.76 KB

This is the patch for 9.2.x. Also applicable to 8.9.x.
Uses exactly same logic as in #4. I just made some changes to improve readability of related code block. The originsl problem was that exposed group filter store operator id in the key $this->options['expose']['operator'] , but at the next step exposed filter read it from $this->options['expose']['operator_id']. As result any filter from exposed grouped filter had used operator from single exposed filter insted of its own.

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.

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.

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.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs Review Queue Initiative, +Needs tests

This issue is being reviewed by the kind folks in Slack, #needs-review-queue-initiative. We are working to keep the size of Needs Review queue [2700+ issues] to around 400 (1 month or less), following Review a patch or merge request as a guide.

Did not test for issue FYI

But this will need a test case to show the issue and that the fix address it.

Thanks!

quietone credited pameeela.

quietone’s picture

Issue summary: View changes
Issue tags: +Bug Smash Initiative

I tested this on Drupal 10.1.x and was able to reproduce the problem.

This is a duplicate of the earlier issue, but let's keep this one as it has more discussion and a patch. I have copied the Issue Summary from that issue because pameeela did a great job of summarizing the issue. This still needs tests.

mohit_aghera’s picture

StatusFileSize
new11.24 KB
new9.48 KB
new9.48 KB

Adding a test case and test only patch.

Note regarding new test-view added:
I tried to modify existing views by adding filter programmatically similar to `FilterBooleanOperatorStringTest`
However, it was not working as expected. I tried with different views from node_test_views module's test views.
It didn't work as expected.
So at last, I ended up creating seperate view for testing purposes.

mohit_aghera’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Status: Needs review » Needs work

The last submitted patch, 19: test-only-3073518-19.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Tested following the issue summary steps and confirmed the issue.
Patch #19 addressed it for me.

Red/green shows good test coverage.

Good job @mohit_aghera with the tests!

  • catch committed fc7aa230 on 10.0.x
    Issue #3073518 by mohit_aghera, rkostov, Eugene Bocharov, rensingh99,...

  • catch committed 3e4a47a1 on 10.1.x
    Issue #3073518 by mohit_aghera, rkostov, Eugene Bocharov, rensingh99,...

  • catch committed 5bac4a0f on 9.5.x
    Issue #3073518 by mohit_aghera, rkostov, Eugene Bocharov, rensingh99,...
catch’s picture

Version: 10.1.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to 10.1.x, cherry-picked to 10.0.x and 9.5.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

pameeela’s picture