diff --git a/rest/dynamodb/dynamodb.py b/rest/dynamodb/dynamodb.py index 9fbc4429..7d93cd53 100644 --- a/rest/dynamodb/dynamodb.py +++ b/rest/dynamodb/dynamodb.py @@ -16,6 +16,8 @@ FAKE_AWS_ACCESS_KEY_ID = "AKIAIOSFODNN7EXAMPLE" FAKE_AWS_SECRET_ACCESS_KEY = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" +USED_RESERVED_WORDS = ["plan"] + class DeploymentTypes(Enum): PRODUCTION = "production" @@ -121,12 +123,17 @@ def update_key(cls, record_id, key, new_value): else: new_value = str(new_value) - updated_item = cls.dynamodb.update_item( + kwargs = dict( TableName=cls.TABLE_NAME, Key={"id": {"S": record_id}}, UpdateExpression="SET {} = :new_content".format(key), ExpressionAttributeValues={":new_content": {data_type: new_value}}, ) + if key in USED_RESERVED_WORDS: + kwargs["UpdateExpression"] = "SET #{} = :new_content".format(key) + kwargs["ExpressionAttributeNames"] = {"#{}".format(key): "{}".format(key)} + + updated_item = cls.dynamodb.update_item(**kwargs) return updated_item @classmethod @@ -316,7 +323,6 @@ def create(cls, data): if __name__ == "__main__": - # To create tables, run: # $ pipenv shell # $ DEPLOYMENT_TYPE="production" ./dynamodb.py