Project

Profile

Help

Issue #6898

Pulp 2 - REST API for Search ignores critera or raises errors when field or filter is specified

Added by Anonymous over 1 year ago. Updated over 1 year ago.

Status:
CLOSED - NOTABUG
Priority:
Normal
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
Due date:
Estimated time:
Severity:
1. Low
Version:
2.16.1
Platform Release:
OS:
CentOS 7
Triaged:
No
Groomed:
No
Sprint Candidate:
No
Tags:
Pulp 2
Sprint:
Quarter:

Description

Detailed Description

Pulp provides REST API at https://docs.pulpproject.org/en/2.21/dev-guide/integration/rest-api/index.html for manipulation users, repositories, content and such.

For Search API https://docs.pulpproject.org/en/2.21/dev-guide/conventions/criteria.html#search-api, pulp provides two options:

  • POST request with criteria object
  • GET request with query arguments

Bug

When searching for units https://docs.pulpproject.org/en/2.21/dev-guide/integration/rest-api/repo/content.html#advanced-unit-search, using GET request it raises error:

Request -> HOSTED_PULP_URL/repositories/external-centos-6-staging/search/units/?field=id&field=display_name&limit=20

Response:

{
   "http_request_method":"GET",
   "exception":[
      "TypeError: pop() takes at most 1 argument (2 given)\n"
   ],
   "error_message":"pop() takes at most 1 argument (2 given)",
   "_href":"/pulp/api/v2/repositories/external-centos-6-staging/search/units/?field=id&field=display_name&limit=20",
   "http_status":500,
   "traceback":[
      "  File \"/usr/lib/python2.7/site-packages/django/core/handlers/base.py\", line 185, in _get_response\n    response = wrapped_callback(request, *callback_args, **callback_kwargs)\n",
      "  File \"/usr/lib/python2.7/site-packages/django/views/generic/base.py\", line 68, in view\n    return self.dispatch(request, *args, **kwargs)\n",
      "  File \"/usr/lib/python2.7/site-packages/django/views/generic/base.py\", line 88, in dispatch\n    return handler(request, *args, **kwargs)\n",
      "  File \"/usr/lib/python2.7/site-packages/pulp/server/webservices/views/decorators.py\", line 241, in _auth_decorator\n    return _verify_auth(self, operation, super_user_only, method, *args, **kwargs)\n",
      "  File \"/usr/lib/python2.7/site-packages/pulp/server/webservices/views/decorators.py\", line 195, in _verify_auth\n    value = method(self, *args, **kwargs)\n",
      "  File \"/usr/lib/python2.7/site-packages/pulp/server/webservices/views/search.py\", line 108, in get\n    return self._generate_response(query, options, *args, **kwargs)\n",
      "  File \"/usr/lib/python2.7/site-packages/pulp/server/webservices/views/repositories.py\", line 285, in _generate_response\n    criteria = UnitAssociationCriteria.from_client_input(query)\n",
      "  File \"/usr/lib/python2.7/site-packages/pulp/server/db/model/criteria.py\", line 286, in from_client_input\n    association_fields = _validate_fields(fields.pop('association', None))\n"
   ]
}

Specifying without field works, even though documentation provides example of using field as query argument.


As for Search using POST request, criteria seems ignored and return everything.

Example critera:

{
  "criteria": {
    "fields": {
      "unit": [
        "name",
        "version"
      ]
    },
    "type_ids": [
      "rpm"
    ],
    "limit": 1
  }
}

Response: Everything (criteria is ignored)

Maybe I'm missing something, but we are not able to get fields we require since the whole output is huge and it downgrades our user experience.

Thank you.

Your Environment

  • Version used: 2.16.4

History

#1 Updated by dkliban@redhat.com over 1 year ago

The POST method is definitely the recommended way to perform filtering. Mostly because you don't have to worry about URL encoding the criteria JSON object.

I noticed that your "fields" object only has a "unit" property. You need to also provide the "association" property with a value of ["created"]. That's what is causing the traceback you posted in the issue.

https://docs.pulpproject.org/en/2.16/dev-guide/conventions/criteria.html#search-criteria

#2 Updated by ipanova@redhat.com over 1 year ago

you need to provide filters in the search criteria.

For example if you want to look for a package with a name 'zebra' and have among displayed fields only its name and checksum, criteria will be the following

{"criteria": {"fields": {"unit": ["name", "checksum"]}, "type_ids": ["rpm"], "filters": {"unit": {"name": "zebra"}}}}

or for example you want to look for a certain range of names

{"criteria": {"fields": {"unit": ["name", "checksum"]}, "type_ids": ["rpm"], "limit": 1, "filters": {"unit": {"name": {"$in": ["fee", "fie", "foe", "foo", "zebra"]}}}}}

If you want to display all rpms from the repo but show only their names and checksum, criteria will be the following

{"criteria": {"fields": {"unit": ["name", "checksum"]}, "type_ids": ["rpm"], "filters": {"unit": {}}}}

#3 Updated by fao89 over 1 year ago

  • Category deleted (14)
  • Status changed from NEW to CLOSED - NOTABUG
  • Tags Pulp 2 added
  • Tags deleted (API Bindings)

Please register to edit this issue

Also available in: Atom PDF