Project

Profile

Help

Issue #5700

closed

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

Added by rmcgover over 4 years ago. Updated over 3 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.

Actions #1

Updated by daviddavis over 4 years ago

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

Added by rajulkumar almost 4 years ago

Revision c675c977 | 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

Actions #2

Updated by ipanova@redhat.com almost 4 years ago

  • Status changed from NEW to POST
Actions #3

Updated by ipanova@redhat.com almost 4 years ago

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

Updated by ipanova@redhat.com almost 4 years ago

  • Triaged changed from No to Yes
Actions #5

Updated by rajulkumar almost 4 years ago

  • Status changed from POST to MODIFIED
Actions #6

Updated by ttereshc almost 4 years ago

  • Platform Release set to 2.21.3

Added by rajulkumar over 3 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)

Actions #8

Updated by ttereshc over 3 years ago

  • Status changed from MODIFIED to CLOSED - CURRENTRELEASE

Also available in: Atom PDF