Project

Profile

Help

Issue #5700

closed

$date operator doesn't work with $and, $or

Added by rmcgover about 5 years ago. Updated over 4 years ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
Due date:
Estimated time:
Severity:
2. Medium
Version:
Platform Release:
2.21.3
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Pulp 2
Sprint:
Quarter:

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.

Also available in: Atom PDF