0

I would like to make my update_item operation idempotent. I have an attribute of type list, and I would like to add a element to list only if not exists. I imagine that i need to use: ConditionExpression

uptd = 'SET status_pedido_disponiveis = list_append(if_not_exists(status_pedido_disponiveis, :empty_list), :my_value)'
attr={ ":my_value": {"L": [{"S": xml }]}, ":empty_list":{"L": [] } }
self.dynamodb.update_item(TableName=self.table_name, Key={'order_id':{'S': order_id}}, 
                          UpdateExpression=uptd, 
                          ExpressionAttributeValues=attr
                          )

1 Answer 1

1

Here is the solution:

uptd = 'SET status_pedido_disponiveis = list_append(if_not_exists(status_pedido_disponiveis, :empty_list), :my_value)'
attr={ ":my_value": {"L": [{"S": xml }]}, ":empty_list":{"L": [] }, ':xml_content': {"S": xml } }
self.dynamodb.update_item(TableName=self.table_name, Key={'order_id':{'S': order_id}}, 
                          UpdateExpression=uptd, 
                          ExpressionAttributeValues=attr,
                          ConditionExpression = "not contains (status_pedido_disponiveis, :xml_content)"
                          )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.