Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AND criteria doesn't return result if one of the conditions/criteria includes date type field #70

Open
rajulkumar opened this issue Nov 8, 2019 · 2 comments

Comments

@rajulkumar
Copy link
Contributor

Summary

AND criteria having one of the criteria with the date type field doesn't return any result.

Same date criteria returns a result if used alone(not as part of AND criteria).

dt = datetime.strptime("2019-11-10T00:00:00Z", "%Y-%m-%dT%H:%M:%SZ")

Criteria.with_field("some_date", Matcher.less_than(dt))

returns a result.
But won't return anything with True criteria within AND or any other possibly matching criteria. e.g.

Criteria.and_(Criteria.true(), 
              Criteria.with_field("some_date", Matcher.less_than(dt)))
Criteria.and_(Criteria.with_field("some_field", Matcher.regex("regex")),
              Criteria.with_field("some_date", Matcher.less_than(dt)))
Criteria.and_(Criteria.with_field("some_other_field", Matcher.equals("value")),
              Criteria.with_field("some_date", Matcher.less_than(dt)))

won't return anything (though there are possible matches).

AND criteria works for any other criteria with non-date fields. .e.g.

Criteria.and_(Criteria.with_field("some_field", Matcher.regex("regex")),
              Criteria.true())
Criteria.and_(Criteria.with_field("some_field", Matcher.regex("regex")),
              Criteria.with_field("some_other_field", Matcher.equals("value")))

returns the result.

Issue Type

  • Bug Report

Steps to reproduce

Create a search request with AND criteria as mentioned in the description involving a date type field and verify with the expected result.

Actual results

search request with AND criteria doesn't return result when one of the conditions includes a date type field.

Expected results

search request with AND criteria should return the expected result even when one of the conditions involve a date type field

OS / Environment

Additional Information

  • Similar request with OR criteria works fine i.e. returns expected result when one of the conditions involves a date type field.
  • Currently, the json query generated for an AND criteria looks something like
{"$and":[{"some_date":{"$lt":{"$date":"2019-11-10T07:24:31Z"}}},{"regex_field":{"$regex": "regex"}}]}

which doesn't return any result. However, if this is modified to

{"some_date":{"$lt":{"$date":"2019-11-10T07:24:31Z"}}, "regex_field":{"$regex": "regex"}}

works fine as an AND criteria and returns the expected result.

@rohanpm
Copy link
Member

rohanpm commented Nov 13, 2019

I was quite surprised by this bug, so I investigated it and I consider it to be a Pulp bug - https://pulp.plan.io/issues/5700.

I think that it needs to be fixed in Pulp, because:

Similar request with OR criteria works fine i.e. returns expected result when one of the conditions involves a date type field.

I don't think this is actually true (Rajul, can you check?)

And although the AND case can be worked around fairly easily by using a dict instead of a list as described here, the same workaround isn't possible for OR.

@jbruzl
Copy link

jbruzl commented Nov 14, 2019

Can we drop this in favor of https://pulp.plan.io/issues/5700 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants