Querying /v2/samples with a q.field of metaquery causes 500

Bug #1426466 reported by Chris Dent
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ceilometer
Fix Released
Medium
ZhiQiang Fan

Bug Description

If you make a request like this:

    - name: list samples with bad field
      url: /v2/samples?q.field=pooon&q.value=cow&q.op=eq
      status: 400
      response_strings:
          - metaquery
          - unrecognized field in query

The response says that metaquery is a valid field, so if you then do this:

    - name: list samples with metaquery field
      url: /v2/samples?q.field=metaquery&q.value=cow&q.op=eq

the server will fail with:

   {"error_message": {"faultcode": "Server", "faultstring": "'unicode' object has no attribute 'iteritems'", "debuginfo": null}}

Traceback below. Presumably the right outcome is a 400. A bad query string shouldn't cause a 5xx of any sort.

Traceback (most recent call last):

  File "/home/cdent/src/ceilometer/.tox/gabbi/lib/python2.7/site-packages/wsmeext/pecan.py", line 82, in callfunction
    result = f(self, *args, **kwargs)

  File "ceilometer/api/controllers/v2/samples.py", line 130, in get_all
    pecan.request.storage_conn.get_samples(f, limit=limit))

  File "ceilometer/storage/pymongo_base.py", line 104, in get_samples
    require_meter=False)

  File "ceilometer/storage/mongo/utils.py", line 152, in make_query_from_filter
    improve_keys(sample_filter.metaquery, metaquery=True))))

  File "/home/cdent/src/ceilometer/.tox/gabbi/lib/python2.7/site-packages/six.py", line 576, in iteritems
    return iter(d.iteritems(**kw))

AttributeError: 'unicode' object has no attribute 'iteritems'

ZhiQiang Fan (aji-zqfan)
Changed in ceilometer:
assignee: nobody → ZhiQiang Fan (aji-zqfan)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to ceilometer (master)

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

Changed in ceilometer:
status: New → In Progress
gordon chung (chungg)
Changed in ceilometer:
milestone: none → kilo-rc1
importance: Undecided → Medium
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to ceilometer (master)

Reviewed: https://review.openstack.org/160074
Committed: https://git.openstack.org/cgit/openstack/ceilometer/commit/?id=e056f6f312d56556d5fb48e8d1281c712d870d87
Submitter: Jenkins
Branch: master

commit e056f6f312d56556d5fb48e8d1281c712d870d87
Author: ZhiQiang Fan <email address hidden>
Date: Sat Feb 28 12:24:16 2015 +0800

    exclude precise metaquery in query field

    We use metaquery as a parameter of db func, and valid keys include
    db func parameters.

    When we parse query filters, the metadata dict is stored as key named
    metaquery in kwargs, and we store q.field=foo as key named foo in kwargs.
    Then if q.field=metaquery, the kwargs will get the key metaquery but
    its type is something, for i.e. string, but not dict. However the db
    func expects metaquery to be a dict but gets a string, then 500 is returned

    This patch returns a 400 error for such case, and removes 'metaquery'
    from valid keys in error message to avoid misleading end user.

    Change-Id: I430717e71a6586d63f267baee29bb71ef8c9eac1
    Closes-Bug: #1426466

Changed in ceilometer:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in ceilometer:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in ceilometer:
milestone: kilo-rc1 → 2015.1.0
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.