Issue #18 new

Update_Item with action "ADD" does not work correctly with string sets

Malcolm Box
created an issue

ddbmock doesn't correctly emulate Dynamo behaviour when ADDing a string set to an item, when the item does not already exist.

Steps to reproduce:

With real Dynamo, execute:

In [1]: from backends.dynamo import get_table

In [2]: t = get_table('polls_votelog')

In [3]: t
Out[3]: Table(mb_polls_votelog)

In [4]: i= t.new_item(hash_key="wibble", range_key="wobble")

In [5]: i.add_attribute('tokens', set(["atoken"]))

In [6]: i.save()
Out[6]: {'ConsumedCapacityUnits': 1.0}

Now with ddbmock:

In [1]: from backends.dynamo import get_table

In [2]: t = get_table('polls_votelog')

In [3]: i= t.new_item(hash_key="wibble", range_key="wobble")

In [4]: i.add_attribute('tokens', set(["atoken"]))

In [5]: i.save()
---------------------------------------------------------------------------
DynamoDBValidationError                   Traceback (most recent call last)
<ipython-input-5-957a4933f20f> in <module>()
----> 1 i.save()

/Users/malcolmbox/dev/tellybug/webserver/lib/python2.7/site-packages/boto/dynamodb/item.pyc in save(self, expected_value, return_values)
    139         """
    140         return self.table.layer2.update_item(self, expected_value,
--> 141                                              return_values)
    142 
    143     def delete(self, expected_value=None, return_values=None):

/Users/malcolmbox/dev/tellybug/webserver/lib/python2.7/site-packages/boto/dynamodb/layer2.pyc in update_item(self, item, expected_value, return_values)
    588                                            attr_updates,
    589                                            expected_value, return_values,
--> 590                                            object_hook=self.dynamizer.decode)
    591         item._updates.clear()
    592         if 'ConsumedCapacityUnits' in response:

/Users/malcolmbox/dev/tellybug/webserver/lib/python2.7/site-packages/boto/dynamodb/layer1.pyc in update_item(self, table_name, key, attribute_updates, expected, return_values, object_hook)
    422         json_input = json.dumps(data)
    423         return self.make_request('UpdateItem', json_input,
--> 424                                  object_hook=object_hook)
    425 
    426     def delete_item(self, table_name, key,

/Users/malcolmbox/dev/tellybug/webserver/lib/python2.7/site-packages/ddbmock/router/boto.pyc in boto_router(self, action, body, object_hook)
     37         ret = router(action, post)
     38     except DDBError as e:
---> 39         raise _ddbmock_exception_to_boto_exception(e)
     40     finally:
     41         boto.log.debug('RequestId: %s', post['request_id'])

DynamoDBValidationError: DynamoDBValidationError: 400 Bad Request
{'message': u"When performing ADD operation on new field, only Numbers or Numbers set are allowed. Got [u'atoken'] of type SS", '__type': 'com.amazonaws.dynamodb.v20111205#ValidationException'}

Comments (1)

  1. Log in to comment