update item fails with 500 error for non-existent item

Bug #1373627 reported by Charles Wang
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
MagnetoDB
Fix Released
Medium
Charles Wang

Bug Description

According to API doc:

update_item
If no item with the specified key is found:
PUT - MagnetoDB creates a new item with the specified primary key, and then adds the attribute.
DELETE - Nothing happens; there is no attribute to delete.
ADD - MagnetoDB creates an item with the supplied primary key and number (or set of numbers) for the attribute value. The only data types allowed are number and number set; no other data types can be specified.

Steps to reproduce:

1. create a table with 3 fields, one field as hash key, one field as range key
2. update_item, with attribute_updates set to a new attribute of type SS, such as
    "attribute_updates": {
        "Tags": {
            "action": "PUT",
          "value": {
            "SS": ["some string"]
          }
        }
3. API returns the following error response:
explanation: "The server has either erred or is incapable of performing the requested operation."
code: 500
-error: {
message: "'NoneType' object has no attribute 'iteritems'"
traceback: null
type: "AttributeError"
}
title: "Internal Server Error"

MagnetoDB log:

2014-09-24 17:21:29.266 15395 ERROR magnetodb.common.middleware.fault [-] 'NoneType' object has no attribute 'iteritems'
Traceback (most recent call last):
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/common/middleware/fault.py", line 118, in process_request
    return req.get_response(self.application)
  File "/Users/charles_wang1/dev/work/magnetodb/.venv/lib/python2.7/site-packages/webob/request.py", line 1320, in send
    application, catch_exc_info=False)
  File "/Users/charles_wang1/dev/work/magnetodb/.venv/lib/python2.7/site-packages/webob/request.py", line 1284, in call_application
    app_iter = application(self.environ, start_response)
  File "/Users/charles_wang1/dev/work/magnetodb/.venv/lib/python2.7/site-packages/webob/dec.py", line 130, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/Users/charles_wang1/dev/work/magnetodb/.venv/lib/python2.7/site-packages/webob/dec.py", line 195, in call_func
    return self.func(req, *args, **kwargs)
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/common/wsgi.py", line 66, in __call__
    response = req.get_response(self.application)
  File "/Users/charles_wang1/dev/work/magnetodb/.venv/lib/python2.7/site-packages/webob/request.py", line 1320, in send
    application, catch_exc_info=False)
  File "/Users/charles_wang1/dev/work/magnetodb/.venv/lib/python2.7/site-packages/webob/request.py", line 1284, in call_application
    app_iter = application(self.environ, start_response)
  File "/Users/charles_wang1/dev/work/magnetodb/.venv/lib/python2.7/site-packages/webob/dec.py", line 144, in __call__
    return resp(environ, start_response)
  File "/Users/charles_wang1/dev/work/magnetodb/.venv/lib/python2.7/site-packages/routes/middleware.py", line 131, in __call__
    response = self.app(environ, start_response)
  File "/Users/charles_wang1/dev/work/magnetodb/.venv/lib/python2.7/site-packages/webob/dec.py", line 144, in __call__
    return resp(environ, start_response)
  File "/Users/charles_wang1/dev/work/magnetodb/.venv/lib/python2.7/site-packages/webob/dec.py", line 130, in __call__
    resp = self.call_func(req, *args, **self.kwargs)
  File "/Users/charles_wang1/dev/work/magnetodb/.venv/lib/python2.7/site-packages/webob/dec.py", line 195, in call_func
    return self.func(req, *args, **kwargs)
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/common/wsgi.py", line 250, in __call__
    action_result = self.execute_action(action, request, **action_args)
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/common/wsgi.py", line 264, in execute_action
    return self.dispatch(self.controller, action, request, **action_args)
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/common/wsgi.py", line 273, in dispatch
    return method(*args, **kwargs)
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/common/probe.py", line 94, in wrapper
    return f(*args, **kwargs)
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/api/openstack/v1/update_item.py", line 108, in process_request
    expected_condition_map=expected_item_conditions)
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/storage/__init__.py", line 295, in update_item
    expected_condition_map
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/storage/manager/simple_impl.py", line 523, in update_item
    expected_condition_map
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/common/probe.py", line 94, in wrapper
    return f(*args, **kwargs)
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/storage/driver/cassandra/cassandra_impl.py", line 1144, in update_item
    key_attribute_map, old_item
  File "/Users/charles_wang1/dev/work/magnetodb/magnetodb/storage/driver/cassandra/cassandra_impl.py", line 1273, in _get_update_conditions
    for attr_name, attr_value in old_item.iteritems():
AttributeError: 'NoneType' object has no attribute 'iteritems'

127.0.0.1 - - [24/Sep/2014 17:21:29] "POST /v1/default_tenant/data/tables/Thread/update_item HTTP/1.1" 500 417 0.009473

Changed in magnetodb:
importance: Undecided → Medium
milestone: none → juno-rc1
Revision history for this message
Charles Wang (charles-wang) wrote :
Changed in magnetodb:
status: New → In Progress
assignee: nobody → Charles Wang (charles-wang)
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to magnetodb (master)

Reviewed: https://review.openstack.org/123927
Committed: https://git.openstack.org/cgit/stackforge/magnetodb/commit/?id=0e0fb8091e50b06f86166b73a8541efd1fb8ec2d
Submitter: Jenkins
Branch: master

commit 0e0fb8091e50b06f86166b73a8541efd1fb8ec2d
Author: Charles Wang <email address hidden>
Date: Wed Sep 24 23:51:15 2014 -0400

    Handle non-existent item when calling update_item

    If update_item action(s) is(are) ADD and/or PUT, a new item
    will be created if expected conditions are satisfied. Otherwise
    ConditionalCheckFailedException will be thrown. If
    action(s) is(are) DELETE only, no operation will be performed
    and a success response will be returned.

    Closes-Bug: #1373627

    Change-Id: Ib58d1433dd546f1472129b669f14a1b689647e1d

Changed in magnetodb:
status: In Progress → Fix Committed
Changed in magnetodb:
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.