Project

Profile

Help

Issue #1332

closed

in Search API, restritcting fields does not work with Mongoengine

Added by amacdona@redhat.com about 9 years ago. Updated over 5 years ago.

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

Description

The `fields` machinery works only with models before the switch to mongoengine.

When sending a criteria object to pymongo, the fields key restricts the fields of the dictionary that is returned. This doesn't work because Mongoengine objects are hydrated from those dictionaries, and instead of leaving them off at serialization time, they are simply set to null values.

$ http --json -a admin:admin --verify=no POST https://localhost/pulp/api/v2/repositories/search/ criteria:='{"filters": {"id": "zoo"}}'
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 296
Content-Type: application/json; charset=utf-8
Date: Thu, 22 Oct 2015 20:32:00 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.16 (Fedora) OpenSSL/1.0.1k-fips mod_wsgi/4.4.8 Python/2.7.10

[
    {
        "_href": "/pulp/api/v2/repositories/zoo/", 
        "_id": {
            "$oid": "562946cfe779894f63353553"
        }, 
        "_ns": "repos", 
        "content_unit_counts": {}, 
        "description": null, 
        "display_name": null, 
        "id": "zoo", 
        "last_unit_added": null, 
        "last_unit_removed": null, 
        "notes": {
            "_repo-type": "rpm-repo"
        }, 
        "scratchpad": {}
    }
]
$ http --json -a admin:admin --verify=no POST https://localhost/pulp/api/v2/repositories/search/ criteria:='{"filters": {"id": "zoo"}, "fields": ["id"]}'
HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 272
Content-Type: application/json; charset=utf-8
Date: Thu, 22 Oct 2015 20:32:11 GMT
Keep-Alive: timeout=5, max=100
Server: Apache/2.4.16 (Fedora) OpenSSL/1.0.1k-fips mod_wsgi/4.4.8 Python/2.7.10

[
    {
        "_href": "/pulp/api/v2/repositories/zoo/", 
        "_id": {
            "$oid": "562946cfe779894f63353553"
        }, 
        "_ns": "repos", 
        "content_unit_counts": {}, 
        "description": null, 
        "display_name": null, 
        "id": "zoo", 
        "last_unit_added": null, 
        "last_unit_removed": null, 
        "notes": {}, 
        "scratchpad": {}
    }
]

Related issues

Blocked by Pulp - Issue #312: It is impossible to use filters with GET search requests, which makes the name of the REST view a bit of a lieCLOSED - CURRENTRELEASEamacdona@redhat.comActions
Blocked by Pulp - Issue #1417: HTTP 500 when invalid fields included as a part of criteria objectsCLOSED - CURRENTRELEASEamacdona@redhat.comActions

Also available in: Atom PDF