release-engineering / pubtools-pulplib

A Pulp library for publishing tools
GNU General Public License v3.0
2 stars 24 forks source link

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

Open rajulkumar opened 5 years ago

rajulkumar commented 5 years ago

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

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

rohanpm commented 5 years ago

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 commented 5 years ago

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