Merge pull request #2329 from swen128/bugfix/dynamodb/update-item
Fix DynamoDB update_item to deal with list-type attributes
This commit is contained in:
commit
d82423788c
@ -298,7 +298,9 @@ class Item(BaseModel):
|
|||||||
new_value = list(update_action['Value'].values())[0]
|
new_value = list(update_action['Value'].values())[0]
|
||||||
if action == 'PUT':
|
if action == 'PUT':
|
||||||
# TODO deal with other types
|
# TODO deal with other types
|
||||||
if isinstance(new_value, list) or isinstance(new_value, set):
|
if isinstance(new_value, list):
|
||||||
|
self.attrs[attribute_name] = DynamoType({"L": new_value})
|
||||||
|
elif isinstance(new_value, set):
|
||||||
self.attrs[attribute_name] = DynamoType({"SS": new_value})
|
self.attrs[attribute_name] = DynamoType({"SS": new_value})
|
||||||
elif isinstance(new_value, dict):
|
elif isinstance(new_value, dict):
|
||||||
self.attrs[attribute_name] = DynamoType({"M": new_value})
|
self.attrs[attribute_name] = DynamoType({"M": new_value})
|
||||||
|
@ -1342,6 +1342,46 @@ def test_query_missing_expr_names():
|
|||||||
resp['Items'][0]['client']['S'].should.equal('test2')
|
resp['Items'][0]['client']['S'].should.equal('test2')
|
||||||
|
|
||||||
|
|
||||||
|
# https://github.com/spulec/moto/issues/2328
|
||||||
|
@mock_dynamodb2
|
||||||
|
def test_update_item_with_list():
|
||||||
|
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
|
||||||
|
|
||||||
|
# Create the DynamoDB table.
|
||||||
|
dynamodb.create_table(
|
||||||
|
TableName='Table',
|
||||||
|
KeySchema=[
|
||||||
|
{
|
||||||
|
'AttributeName': 'key',
|
||||||
|
'KeyType': 'HASH'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
AttributeDefinitions=[
|
||||||
|
{
|
||||||
|
'AttributeName': 'key',
|
||||||
|
'AttributeType': 'S'
|
||||||
|
},
|
||||||
|
],
|
||||||
|
ProvisionedThroughput={
|
||||||
|
'ReadCapacityUnits': 1,
|
||||||
|
'WriteCapacityUnits': 1
|
||||||
|
}
|
||||||
|
)
|
||||||
|
table = dynamodb.Table('Table')
|
||||||
|
table.update_item(
|
||||||
|
Key={'key': 'the-key'},
|
||||||
|
AttributeUpdates={
|
||||||
|
'list': {'Value': [1, 2], 'Action': 'PUT'}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
resp = table.get_item(Key={'key': 'the-key'})
|
||||||
|
resp['Item'].should.equal({
|
||||||
|
'key': 'the-key',
|
||||||
|
'list': [1, 2]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
# https://github.com/spulec/moto/issues/1342
|
# https://github.com/spulec/moto/issues/1342
|
||||||
@mock_dynamodb2
|
@mock_dynamodb2
|
||||||
def test_update_item_on_map():
|
def test_update_item_on_map():
|
||||||
|
Loading…
Reference in New Issue
Block a user