2016-08-09 51 views
0

Ich möchte meine update_item Operation idempotent machen. Ich habe ein Attribut der Typenliste, und ich möchte ein Element nur dann zur Liste hinzufügen, wenn es nicht existiert. Ich stelle mir vor, dass ich verwenden müssen: ConditionExpressionDynamodb machen update_item idempotent - Listenattribut

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 
         ) 

Antwort

1

Hier ist die Lösung:

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)" 
         )