HTTP 500 from an invalid sort_key

Bug #1450552 reported by Ruby Loo
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ironic
Fix Released
Low
Ruby Loo

Bug Description

If you specify an invalid sort_key, Ironic returns an HTTP 500 Internal Server Error. It would be better if it were an HTTP 400 Bad Request, with some useful message.

See related bug in the client: https://launchpad.net/bugs/1443003

eg:

curl -i -X GET http://localhost:6385/v1/ports/?sort_key=foo
HTTP/1.0 500 Internal Server Error
Date: Thu, 30 Apr 2015 16:34:36 GMT
Server: WSGIServer/0.1 Python/2.7.5
X-OpenStack-Ironic-API-Minimum-Version: 1.1
X-OpenStack-Ironic-API-Maximum-Version: 1.6
X-OpenStack-Ironic-API-Version: 1.1
Content-Type: application/json
Content-Length: 92

{"error_message": "{\"debuginfo\": null, \"faultcode\": \"Server\", \"faultstring\": \"\"}"}

----------------
from ironic-api:

127.0.0.1 - - [30/Apr/2015 16:32:39] "GET /v1/ports/?sort_key=asc HTTP/1.1" 500 92
2015-04-30 16:34:36.425 25797 ERROR wsme.api [-] Server-side error: "". Detail:
Traceback (most recent call last):
  File "/home/rloo/ironic/.tox/venv/lib/python2.7/site-packages/wsmeext/pecan.py", line 82, in callfunction
    result = f(self, *args, **kwargs)
  File "/home/rloo/ironic/ironic/api/controllers/v1/port.py", line 261, in get_all
    limit, sort_key, sort_dir)
  File "/home/rloo/ironic/ironic/api/controllers/v1/port.py", line 209, in _get_ports_collection
    sort_dir=sort_dir)
  File "/home/rloo/ironic/ironic/objects/base.py", line 109, in wrapper
    result = fn(cls, context, *args, **kwargs)
  File "/home/rloo/ironic/ironic/objects/port.py", line 126, in list
    sort_dir=sort_dir)
  File "/home/rloo/ironic/ironic/db/sqlalchemy/api.py", line 406, in get_port_list
    sort_key, sort_dir)
  File "/home/rloo/ironic/ironic/db/sqlalchemy/api.py", line 144, in _paginate_query
    marker=marker, sort_dir=sort_dir)
  File "/home/rloo/ironic/.tox/venv/lib/python2.7/site-packages/oslo_db/sqlalchemy/utils.py", line 155, in paginate_query
    raise exception.InvalidSortKey()
InvalidSortKey
127.0.0.1 - - [30/Apr/2015 16:34:36] "GET /v1/ports/?sort_key=asc HTTP/1.1" 500 92

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to ironic (master)

Fix proposed to branch: master
Review: https://review.openstack.org/179159

Changed in ironic:
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to ironic (master)

Reviewed: https://review.openstack.org/179159
Committed: https://git.openstack.org/cgit/openstack/ironic/commit/?id=243128ecf41763d49cca4a21468826b6f33f3f00
Submitter: Jenkins
Branch: master

commit 243128ecf41763d49cca4a21468826b6f33f3f00
Author: Ruby Loo <email address hidden>
Date: Thu Apr 30 16:49:26 2015 +0000

    Return HTTP 400 for invalid sort_key

    HTTP 500 (Internal Server Error) was being returned when a
    request (eg node-list) specified an invalid sort_key. This is
    because a DB exception was being raised that we weren't
    handling.

    We now raise an InvalidParameterValue exception with a message
    that indicates that the sort key is invalid. The response is now
    an HTTP 400 (Bad Request).

    Change-Id: I237856ccb10e395bf2b42307804f607963b5dcbb
    Closes-Bug: #1450552

Changed in ironic:
status: In Progress → Fix Committed
Changed in ironic:
milestone: none → 4.0.0
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.