Problem/Motivation

When a filter criterion is NULL, zero, or the empty string, FilterBuilder logs a warning for "Invalid condition." Let's say that we have a field on nodes called "field_archived", and we want to only return nodes that have a value of zero or NULL on this field. Because the FilterBuilder is validating the condition by checking for a non-falsey value, it will incorrectly flag this condition as invalid (even though the condition will still be applied).

Steps to reproduce

  1. Create a checkbox field called field_archived on a content-type. The checkbox should be backed by a value of '1'.
  2. Configure a search to filter on this field, returning only nodes in which this checkbox is unchecked.
  3. With dblog enabled, run the search.
  4. Observe that dblog has logged a message saying either Invalid condition field_archived = '0' or Invalid condition field_archived = NULL

Proposed resolution

In FilterBuilder::buildFilters(), do not check $condition->getValue() for falsiness when validating the condition.

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

None.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

daniel_j created an issue. See original summary.

daniel_j’s picture

kim.pepper’s picture

Status: Active » Needs review
kristiaanvandeneynde’s picture

Version: 2.0.0-beta1 » 2.x-dev

Different approach, actually check for NULL. Will open an MR.

kim.pepper’s picture

Status: Needs review » Fixed

Committed to 2.x and 3.x. Thanks!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

  • kim.pepper committed 62aad6b5 on 3.x
    [#3372023] fix: When filter value is falsey, irrelevant warnings written...

Status: Fixed » Closed (fixed)

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