Project

Profile

Help

Issue #5700

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

Added by rmcgover 9 months ago. Updated 30 days ago.

Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
-
Category:
-
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:

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.

Associated revisions

Revision c675c977 View on GitHub
Added by rajulkumar 3 months ago

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

Revision 80fff3ec View on GitHub
Added by rajulkumar about 1 month ago

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)

History

#1 Updated by daviddavis 9 months ago

  • Tracker changed from Issue to Task
  • % Done set to 0

#2 Updated by ipanova@redhat.com 3 months ago

  • Status changed from NEW to POST

#3 Updated by ipanova@redhat.com 2 months ago

  • Tracker changed from Task to Issue
  • Severity set to 2. Medium
  • Triaged set to No

#4 Updated by ipanova@redhat.com 2 months ago

  • Triaged changed from No to Yes

#5 Updated by rajulkumar 2 months ago

  • Status changed from POST to MODIFIED

#6 Updated by LaurendeSouza about 2 months ago

Glad to found this informative post. I am senior cv writer and serving accountant cv writing service https://www.cvfolks.co.uk/accountant-cv/ with timed delivery at affordable piece.

#7 Updated by ttereshc about 2 months ago

  • Platform Release set to 2.21.3

#9 Updated by ttereshc 30 days ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Please register to edit this issue

Also available in: Atom PDF