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
- Create a checkbox field called
field_archivedon a content-type. The checkbox should be backed by a value of '1'. - Configure a search to filter on this field, returning only nodes in which this checkbox is unchecked.
- With dblog enabled, run the search.
- Observe that dblog has logged a message saying either
Invalid condition field_archived = '0'orInvalid 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.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | search_api_opensearch-3372023-2-suppress_falsey_warnings.patch | 735 bytes | daniel_j |
Issue fork search_api_opensearch-3372023
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
Comment #2
daniel_j commentedComment #3
kim.pepperComment #4
kristiaanvandeneyndeDifferent approach, actually check for NULL. Will open an MR.
Comment #7
kim.pepperCommitted to 2.x and 3.x. Thanks!