Warning: Invalid condition field = NULL

Created on 23 January 2025, 3 months ago

Problem/Motivation

Site log is spammed with the next warning:

Invalid condition field_category = NULL

Steps to reproduce

Add filter with "empty" condition to any Search Api view.

Looks like it also happens on 0 values of numeric filter.

Proposed resolution

There is the next check:

        if (!$condition->getField() || !$condition->getValue() || !$condition->getOperator()) {
          // @todo When using views the sort field is coming as a filter and
          // messing with this section.
          $this->logger->warning("Invalid condition %condition", ['%condition' => $condition]);
        }

Which checks for "!$condition->getValue()", but NULL value is valid value for empty filter, same as 0 for numeric one.

I think this condition should be removed.

🐛 Bug report
Status

Active

Version

8.0

Component

Code

Created by

🇧🇾Belarus dewalt

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

Merge Requests

Comments & Activities

  • Issue created by @dewalt
  • 🇮🇳India hetal.solanki

    @dewalt

    I have review and try to apply patch and it's working for me.

    So moving this issue to RTBC

    Thank you!!

  • First commit to issue fork.
  • 🇨🇦Canada mparker17 UTC-4

    The patch looks fine to me, but I'm having trouble reproducing the issue (and if I can reproduce it manually, then I can add a test) with the instructions provided, i.e.:

    Add filter with "empty" condition to any Search Api view.

    Looks like it also happens on 0 values of numeric filter.

    @dewalt or @hetal.solanki, could either of you add some more details?

    Here's what I've tried...

    1. Run the steps to set up a local environment, including apply the patch or switching to the issue fork (I used the issue fork but either will work)
    2. Edit the test view at /admin/structure/views/view/test_elasticsearch_index_search
    3. Under Filter criteria, click the Add button
    4. Check Category, click the Add and configure filter criteria button
    5. Set Operator to Is empty (NULL)
    6. Click the Apply button
    7. Click the Save button on the view
    8. Go to the test view at /test-elasticsearch-index-search
    9. Observe that the results are filtered
    10. Go to /admin/reports/dblog
      • Expected behavior: I see the error Invalid condition category = NULL
      • Actual behavior: The error log is empty
    11. Edit the test view at /admin/structure/views/view/test_elasticsearch_index_search
    12. Under Filter criteria, choose And/Or Rearrange from the drop-button
    13. Click Remove in the Test entity - mul changed revisions and data table datasource: Category = row, i.e.: to delete the test filter added in the previous test
    14. Under Filter criteria, click the Add button
    15. Check Width, click the Add and configure filter criteria button
    16. Set Operator to Is equal to, and set Value to 0
    17. Click the Apply button
    18. Click the Save button on the view
    19. Go to the test view at /test-elasticsearch-index-search
    20. Observe that the results are filtered
    21. Go to /admin/reports/dblog
      • Expected behavior: I see the error Invalid condition category = NULL
      • Actual behavior: The error log is empty
  • 🇨🇦Canada mparker17 UTC-4

    (whoops, wrong status, I should have changed it to "maintainer needs more info"... when you add more steps to reproduce, please change it back to RTBC)

  • 🇫🇮Finland sokru

    I guess it might be related by some faulty Search API configuration or source data issue, but on the other hand search_api_opensearch module has this change committed since day 0 https://git.drupalcode.org/project/search_api_opensearch/-/blob/3.x/src/...

Production build 0.71.5 2024