Question

The new interface does not seem to expose the ADD functionality for updates. I would like to do something like:

my_item = my_table.get_item(key=my_key,hash=my_hash)
my_item.add_attribute('count_votes',1)
my_item.partial_save()

It seems that in prior versions this would work. In 2.25 i am getting: AttributeError: 'Item' object has no attribute 'add_attribute'

Was it helpful?

Solution

You are right, this add_attribute is not present now. Looks like you need to use update_item api on boto.dynamodb.layer1.

Adding a working code - I tried on DynamoDB local:

conn.update_item(
    "table-1",
    {"firstKey":{"S":"12345"}},
    {"counter":{"Action":"ADD","Value":{"N":"1"}}}
)

Here it increments counter by 1 on table which has "firstKey" as the Hashkey.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top