KeyError: ‘Action’ when trying to mock DynamoDB

Moto code where the crash happens is here: github.com/spulec/moto/blob/master/moto/dynamodb2/models/init.py#L112:

def update_with_attribute_updates(self, attribute_updates):
    for attribute_name, update_action in attribute_updates.items():
        action = update_action["Action"]

where the Action is expected to be passed, even though in Boto3 DynamoDB.Client.update_item() you don’t have to, since a default value exists for that parameter.

That’s why the code to-be-tested was running well anyway. Documentation confirms this too (emphasis mine):

Action (string) –Specifies how to perform the update. Valid values are PUT (default), …

So, this error came from a Boto3 and Moto discrepancy.

Short term fix:

Change this:

dataclass_attributes[current_field.name] = {'Value': attribute_value}

to:

dataclass_attributes[current_field.name] = {'Value': attribute_value, 'Action': 'Put'}

However, I created a GitHub issue, and I am going to open a pull request with a fix, so that future users won’t have the same (customer) experience. Edit: Bug-fix just got merged!

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top