Actions
Issue #981
closedAPI searches using critera fail with 500 instead of 400 (bad request) for invalid mongo queries
Status:
CLOSED - CURRENTRELEASE
Priority:
Normal
Assignee:
Category:
-
Sprint/Milestone:
-
Start date:
Due date:
Estimated time:
Severity:
3. High
Version:
Platform Release:
2.8.0
OS:
Triaged:
Yes
Groomed:
No
Sprint Candidate:
No
Tags:
Pulp 2
Sprint:
Quarter:
Description
The API searches using critera fail with 500 for invalid mongo queries. This should fail with 400 (bad request).
For example, using an invalid operator in the query.
$ curl -i -H "Accept: application/json" -H "WebFrameworkSwitch: django" -X POST -k -u admin:admin "https://localhost/pulp/api/v2/repositoriesearch/" -d '{"criteria":{"filters":{"repo_id":{"$eq":"jeff"}}}}'
HTTP/1.1 500 INTERNAL SERVER ERROR
Date: Wed, 13 May 2015 15:18:22 GMT
Server: Apache/2.4.10 (Fedora) OpenSSL/1.0.1k-fips mod_wsgi/4.3.2 Python/2.7.8
Content-Encoding: utf-8
Content-Length: 2277
Connection: close
Content-Type: application/json
{"http_request_method": "POST", "exception": ["OperationFailure: database error: invalid operator: $eq\n"], "error_message": "database error: invalid operator: $eq", "_href": "/pulp/api/v2/repositories/search/", "http_status": 500, "traceback": [" File \"/usr/lib/python2.7/site-packages/django/core/handlers/base.py\", line 112, 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 69, in view\n return self.dispatch(request, *args, **kwargs)\n", " File \"/usr/lib/python2.7/site-packages/django/views/generic/base.py\", line 87, in dispatch\n return handler(request, *args, **kwargs)\n", " File \"/home/jortel/git/pulp/server/pulp/server/webservices/views/decorators.py\", line 237, in _auth_decorator\n return _verify_auth(self, operation, super_user_only, method, *args, **kwargs)\n", " File \"/home/jortel/git/pulp/server/pulp/server/webservices/views/decorators.py\", line 191, in _verify_auth\n value = method(self, *args, **kwargs)\n", " File \"/home/jortel/git/pulp/server/pulp/server/webservices/views/util.py\", line 110, in wrapper\n return func(*args, **kwargs)\n", " File \"/home/jortel/git/pulp/server/pulp/server/webservices/views/search.py\", line 109, in post\n return self._generate_response(query, options, *args, **kwargs)\n", " File \"/home/jortel/git/pulp/server/pulp/server/webservices/views/search.py\", line 140, in _generate_response\n return cls.response_builder(cls.get_results(query, search_method, options, *args, **kwargs))\n", " File \"/home/jortel/git/pulp/server/pulp/server/webservices/views/repositories.py\", line 313, in get_results\n results = list(search_method(query))\n", " File \"/usr/lib64/python2.7/site-packages/pymongo/cursor.py\", line 814, in next\n if len(self.__data) or self._refresh():\n", " File \"/usr/lib64/python2.7/site-packages/pymongo/cursor.py\", line 763, in _refresh\n self.__uuid_subtype))\n", " File \"/usr/lib64/python2.7/site-packages/pymongo/cursor.py\", line 720, in __send_message\n self.__uuid_subtype)\n", " File \"/usr/lib64/python2.7/site-packages/pymongo/helpers.py\", line 100, in _unpack_response\n error_object[\"$err\"])\n"]}
Actions
wrap the use of criteria to catch invalid criteria objects
closes: #981