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.
Updated by daviddavis about 5 years ago
- Tracker changed from Issue to Task
- % Done set to 0
Added by rajulkumar over 4 years ago
Updated by ipanova@redhat.com over 4 years ago
- Status changed from NEW to POST
Updated by ipanova@redhat.com over 4 years ago
- Tracker changed from Task to Issue
- Severity set to 2. Medium
- Triaged set to No
Updated by rajulkumar over 4 years ago
- Status changed from POST to MODIFIED
Applied in changeset pulp|c675c977d922cff3326cc030fe6fffbd7c0274dd.
Added by rajulkumar over 4 years ago
Revision 80fff3ec | View on GitHub
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
(cherry picked from commit c675c977d922cff3326cc030fe6fffbd7c0274dd)
Updated by rajulkumar over 4 years ago
Applied in changeset pulp|80fff3ec604492e3d70dc346059685529c691167.
Updated by ttereshc over 4 years ago
- Status changed from MODIFIED to CLOSED - CURRENTRELEASE
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