Issue #1332
closedin Search API, restritcting fields does not work with Mongoengine
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
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
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
Updated by amacdona@redhat.com about 9 years ago
- Status changed from NEW to ASSIGNED
Updated by amacdona@redhat.com about 9 years ago
- Status changed from ASSIGNED to NEW
Updated by amacdona@redhat.com almost 9 years ago
- Status changed from NEW to ASSIGNED
- Assignee set to amacdona@redhat.com
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
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
Added by Austin Macdonald almost 9 years ago
Updated by Anonymous almost 9 years ago
- Status changed from POST to MODIFIED
- % Done changed from 0 to 100
Applied in changeset pulp|8860d82d6f70ed2c8202af89bc752ee31b75dbf4.
Updated by dkliban@redhat.com almost 9 years ago
- Status changed from MODIFIED to 5
Updated by dkliban@redhat.com over 8 years ago
- Status changed from 5 to CLOSED - CURRENTRELEASE
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:
- http://pulp-smash.readthedocs.io/en/latest/api/pulp_smash.tests.platform.api_v2.test_search.html#pulp_smash.tests.platform.api_v2.test_search.FieldTestCase
- http://pulp-smash.readthedocs.io/en/latest/api/pulp_smash.tests.platform.api_v2.test_search.html#pulp_smash.tests.platform.api_v2.test_search.FieldsTestCase
Updated by Ichimonji10 over 8 years ago
Updated by bmbouter over 8 years ago
- Status changed from CLOSED - CURRENTRELEASE to NEW
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"
}
]
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
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
.