V8-archive: Filter logical operator "OR" not working

Created on 8 Nov 2019  路  6Comments  路  Source: directus/v8-archive

Bug Report

This happens with APP 7.10.0 and API 2.6.0.

When using logical operator "OR" with filter query parameters in a API request, the response include results satisfying only the first predicate thus ignoring the OR and the second part.

Steps to Reproduce

  1. Add a custom collection
  2. Create a collection element with property content_max_age set to 2020-10-15
  3. Create a collection element with property content_max_age left blank (thus saved in DB as null)
  4. Make an API request as following:
    {{ENDPOINT}}/_/items/banner_item?filter[content_max_age][eq]=2020-10-15&filter[content_max_age][logical]=or&filter[content_max_age][null]
    or
    {{ENDPOINT}}/_/items/banner_item?filter[content_max_age][eq]=2020-10-15&filter[content_max_age][logical]=or&filter[content_max_age][empty]
  5. Check API response body

Expected Behaviour

The API response body should include:

  1. element created at step 1 (content_max_age set to 2020-10-15)
  2. element created at step 2 (content_max_age left blank - null in database)

Actual Behaviour

The API response body includes only:

  1. element created at step 1 (content_max_age set to 2020-10-15)

Other Context & Screenshots

image

image

bug api

Most helpful comment

Hei guys, got an update on this.

I realises inverting the order of the filter parameters it works! Just as mentioned by @itsmerhp but with a little change:

This call will return valid results:
{{ENDPOINT}}/_/items/banner_item?filter[content_max_age][0][null]&filter[content_max_age][1][logical]=or&filter[content_max_age][1][gte]=2020-02-19

image

while this one will not return results
{{ENDPOINT}}/_/items/banner_item?fields=content_max_age,id&filter[content_max_age][0][eq]=2020-10-15&filter[content_max_age][1][logical]=or&filter[content_max_age][1][null]
image

Basically the query param with the NULL value must be the first one of the phrase!

Thank you for all your support!

All 6 comments

Hello @lucianospi
Please try with below filters :

Logical operator for same field : {{ENDPOINT}}/_/items/banner_item?filter[content_max_age][0][eq]=2020-10-15&filter[content_max_age][1][logical]=or&filter[content_max_age][1][null]

Logical operator for different fields : {{ENDPOINT}}/_/items/banner_item?filter[content_max_age][eq]=2020-10-15&filter[id][logical]=OR&filter[id][in]=1,2

@lucianospi - May I please have an update on the solution which is provided by @itsmerhp ?

@lucianospi - 馃敂

Screenshot 2020-01-08 at 12 46 46
Screenshot 2020-01-08 at 12 48 49
Hello guys, apologises for the late feedback. I had a go with the suggestions provided by @itsmerhp . Unfortunately none worked.

As you can see in the screenshots, there are existing elements with field "content_max_age" set as null. However that is not returned when using the logical operator OR in the filters.

Hei guys, got an update on this.

I realises inverting the order of the filter parameters it works! Just as mentioned by @itsmerhp but with a little change:

This call will return valid results:
{{ENDPOINT}}/_/items/banner_item?filter[content_max_age][0][null]&filter[content_max_age][1][logical]=or&filter[content_max_age][1][gte]=2020-02-19

image

while this one will not return results
{{ENDPOINT}}/_/items/banner_item?fields=content_max_age,id&filter[content_max_age][0][eq]=2020-10-15&filter[content_max_age][1][logical]=or&filter[content_max_age][1][null]
image

Basically the query param with the NULL value must be the first one of the phrase!

Thank you for all your support!

Awesome! Can we get this added to the docs?

@directus/api ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ondronix picture ondronix  路  3Comments

jwkellyiii picture jwkellyiii  路  3Comments

Nitwel picture Nitwel  路  3Comments

metalmarco picture metalmarco  路  3Comments

Varulv1997 picture Varulv1997  路  3Comments