Project

Profile

Help

Issue #1332

in Search API, restritcting fields does not work with Mongoengine

Added by amacdona@redhat.com almost 5 years ago. Updated over 1 year 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 - CURRENTRELEASE<a title="Actions" class="icon-only icon-actions js-contextmenu" href="#">Actions</a>
Blocked by Pulp - Issue #1417: HTTP 500 when invalid fields included as a part of criteria objectsCLOSED - CURRENTRELEASE<a title="Actions" class="icon-only icon-actions js-contextmenu" href="#">Actions</a>

Associated revisions

Revision 8860d82d View on GitHub
Added by Austin Macdonald over 4 years ago

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.

Revision 8860d82d View on GitHub
Added by Austin Macdonald over 4 years ago

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.

History

#1 Updated by mhrivnak almost 5 years ago

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

#2 Updated by amacdona@redhat.com almost 5 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

#3 Updated by amacdona@redhat.com almost 5 years ago

  • Status changed from NEW to ASSIGNED

#4 Updated by amacdona@redhat.com almost 5 years ago

  • Status changed from ASSIGNED to NEW

#5 Updated by amacdona@redhat.com almost 5 years ago

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

#6 Updated by amacdona@redhat.com almost 5 years ago

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

#7 Updated by amacdona@redhat.com almost 5 years ago

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

#8 Updated by Anonymous over 4 years ago

  • Status changed from POST to MODIFIED
  • % Done changed from 0 to 100

#9 Updated by dkliban@redhat.com over 4 years ago

  • Status changed from MODIFIED to 5

#10 Updated by dkliban@redhat.com over 4 years ago

  • Status changed from 5 to CLOSED - CURRENTRELEASE

#11 Updated by Ichimonji10 over 4 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:

#13 Updated by bmbouter over 4 years ago

  • Status changed from CLOSED - CURRENTRELEASE to NEW

#14 Updated by bmbouter over 4 years ago

  • Triaged changed from Yes to No

#15 Updated by bmbouter over 4 years ago

  • Platform Release deleted (2.8.0)

#16 Updated by amacdona@redhat.com over 4 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"
    }
]

#17 Updated by amacdona@redhat.com over 4 years ago

  • Status changed from NEW to CLOSED - CURRENTRELEASE

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

#18 Updated by bmbouter over 1 year ago

  • Tags Pulp 2 added

Please register to edit this issue

Also available in: Atom PDF