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
Actions #1

Updated by mhrivnak about 9 years ago

  • Priority changed from Normal to High
  • Platform Release set to 2.8.0
  • Triaged changed from No to Yes
Actions #2

Updated by amacdona@redhat.com about 9 years ago

  • Blocked by Issue #312: It is impossible to use filters with GET search requests, which makes the name of the REST view a bit of a lie added
Actions #3

Updated by amacdona@redhat.com about 9 years ago

  • Status changed from NEW to ASSIGNED
Actions #4

Updated by amacdona@redhat.com about 9 years ago

  • Status changed from ASSIGNED to NEW
Actions #5

Updated by amacdona@redhat.com almost 9 years ago

  • Status changed from NEW to ASSIGNED
  • Assignee set to amacdona@redhat.com
Actions #6

Updated by amacdona@redhat.com almost 9 years ago

  • Blocked by Issue #1417: HTTP 500 when invalid fields included as a part of criteria objects added
Actions #7

Updated by amacdona@redhat.com almost 9 years ago

  • Status changed from ASSIGNED to POST
  • Version set to 2.7.0

Added by Austin Macdonald almost 9 years ago

Revision 8860d82d | View on GitHub

Allow restriction of fields on Mongoengine documents

closes #1332 cloese #1417

Remove unspecified, nonrequired key value pairs from serialized results when searching by a criteria object that specifies fields.

Added by Austin Macdonald almost 9 years ago

Revision 8860d82d | View on GitHub

Allow restriction of fields on Mongoengine documents

closes #1332 cloese #1417

Remove unspecified, nonrequired key value pairs from serialized results when searching by a criteria object that specifies fields.

Actions #8

Updated by Anonymous almost 9 years ago

  • Status changed from POST to MODIFIED
  • % Done changed from 0 to 100
Actions #9

Updated by dkliban@redhat.com almost 9 years ago

  • Status changed from MODIFIED to 5
Actions #10

Updated by dkliban@redhat.com over 8 years ago

  • Status changed from 5 to CLOSED - CURRENTRELEASE
Actions #11

Updated by Ichimonji10 over 8 years ago

This is broken in 2.8.3. As an example, given an HTTP GET request to https://pulp.example.com/pulp/api/v2/users/search/?field=name, the following response might be returned:

[{u'_href': u'/pulp/api/v2/users/None/',
  u'_id': {u'$oid': u'5734c946e8ec9868b57fc652'},
  u'login': None,
  u'name': u'admin'},
 {u'_href': u'/pulp/api/v2/users/None/',
  u'_id': {u'$oid': u'5734d925e8ec98692112327b'},
  u'login': None,
  u'name': u'46f0b926-891b-4567-b6f8-fbe19e2e0c7c'},
 {u'_href': u'/pulp/api/v2/users/None/',
  u'_id': {u'$oid': u'5734d926e8ec986922fdec16'},
  u'login': None,
  u'name': u'051a9641-3e9d-47ad-9635-3b68e0b29d9b'},
 {u'_href': u'/pulp/api/v2/users/None/',
  u'_id': {u'$oid': u'5734d927e8ec986920331c71'},
  u'login': None,
  u'name': u'71195cb7-855e-4c83-8174-8169060d30ec'}]

The following Pulp Smash test cases demonstrate this issue:

Actions #13

Updated by bmbouter over 8 years ago

  • Status changed from CLOSED - CURRENTRELEASE to NEW
Actions #14

Updated by bmbouter over 8 years ago

  • Triaged changed from Yes to No
Actions #15

Updated by bmbouter over 8 years ago

  • Platform Release deleted (2.8.0)
Actions #16

Updated by amacdona@redhat.com over 8 years ago

A quick check makes me think this is restricted to users.This should be filed as a new bug.

$ http --verify no --auth admin:admin GET https://localhost/pulp/api/v2/repositories/search/?field=id

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Length: 103
Content-Type: application/json; charset=utf-8
Date: Fri, 13 May 2016 14:27:57 GMT
Keep-Alive: timeout=5, max=10000
Server: Apache/2.4.18 (Fedora) OpenSSL/1.0.2d-fips mod_wsgi/4.4.8 Python/2.7.11
[
    {
        "_href": "/pulp/api/v2/repositories/zoo/", 
        "_id": {
            "$oid": "5735e3dee779890d0493972e"
        }, 
        "id": "zoo"
    }
]
Actions #17

Updated by amacdona@redhat.com over 8 years ago

  • Status changed from NEW to CLOSED - CURRENTRELEASE

Closing because this is a new bug: https://pulp.plan.io/issues/1933

Actions #18

Updated by bmbouter over 5 years ago

  • Tags Pulp 2 added

Also available in: Atom PDF