Issue #5700
closed$date operator doesn't work with $and, $or
Description
Pulp 2.x supports a "$date" operator extension for queries, documented here: https://docs.pulpproject.org/dev-guide/conventions/criteria.html#search-criteria
This doesn't work in conjunction with mongo $and or $or operators. Such queries won't match as expected. No such limitations are documented.
Steps to reproduce¶
In development environment:
1. Do a search using $date, to confirm it's generally working.
$ curl -H 'Content-type: application/json' -d '{"criteria": {"limit": 1, "filters": {"last_unit_added": {"$lt": {"$date": "4000-01-01T00:00:00Z"}}}}}' -u admin:admin -k https://localhost/pulp/api/v2/repositories/search/
[{"scratchpad": {}, "display_name": null, "description": null, "last_unit_added": "2019-11-03T23:29:01Z", "notes": {"_repo-type": "rpm-repo"}, "last_unit_removed": null, "content_unit_counts": {"modulemd_defaults": 1}, "_ns": "repos", "_id": {"$oid": "5d5f258630f2523490962da7"}, "id": "zoo", "_href": "/pulp/api/v2/repositories/zoo/"}]
2. Do the same search again but wrapping the criteria with $and.
$ curl -H 'Content-type: application/json' -d '{"criteria": {"limit": 1, "filters": {"$and": [{"last_unit_added": {"$lt": {"$date": "4000-01-01T00:00:00Z"}}}]}}}' -u admin:admin -k https://localhost/pulp/api/v2/repositories/search/
[]
Actual results¶
Search (2) returns empty results.
Expected results¶
One of these in order of preference:
- Search (2) returns exactly the same result as search (1).
- OR, this search gives an error rather than silently giving the wrong results.
- OR, the Pulp documentation explains where $date can and can't be used.
Additional info¶
If I look at DateOperator in server/pulp/server/db/model/criteria.py, I can see that there's no attempt to descend into anything other than dicts. If there are mongo operators other than $and/$or which also use arrays, they'd presumably be affected as well.
Fix $date operator to work with $and or $or
Queries with $date operator doesn't work as expected with $and or $or operators. $date operator descends only on dicts and ignores everything else. This fix modifies $date operator to descend on list too so it work with $and or $or operators.
Closes #5700