test
test

Reputation: 153

Transaction request cannot include multiple operations on one item python

While using transact_write_item, I am facing below error:

An error occurred (ValidationException) when calling the TransactWriteItems operation: Transaction request cannot include multiple operations on one item

Below is my code:

dynamodb.transact_write_items(
  TransactItems=[
   {
      "Update":{
         "Key":{
            "id":{
               "S":"8177-4cb6ca9ede00"
            }
         },
         "TableName":"user",
         "UpdateExpression":"SET #updated_at = :updated_at",
         "ExpressionAttributeNames":{
            "#updated_at":"updated_at"
         },
         "ExpressionAttributeValues":{
            ":updated_at":{
               "N":"1607588602447"
            }
         },
         "ConditionExpression":"attribute_exists(id)"
      }
   },
   {
      "Delete":{
         "Key":{
            "key":{
               "S":"00e4d492d86284ebf48a"
            }
         },
         "TableName":"user_name",
         "ConditionExpression":"#i = :i",
         "ExpressionAttributeNames":{
            "#i":"name"
         },
         "ExpressionAttributeValues":{
            ":i":{
               "S":"00e4d492d86284ebf48a"
            }
         }
      }
   },
   {
      "Put":{
         "Item":{
            "name":{
               "S":"700e4d492d86284ebf48a"
            }
         },
         "TableName":"user_name",
         "ConditionExpression":"#i <> :i",
         "ExpressionAttributeNames":{
            "#i":"name"
         },
         "ExpressionAttributeValues":{
            ":i":{
               "S":"700e4d492d86284ebf48a"
            }
         }
      }
   }
]
)

What am I missing? However if I perform a single action, it works.

Upvotes: 3

Views: 8637

Answers (2)

digitalkaoz
digitalkaoz

Reputation: 21

while they point to the same item, they use different exclusive conditions. (came here with the same problem, without a solution)

Delete

"ConditionExpression":"#i = :i",

Put

"ConditionExpression":"#i <> :i",

so i would consider it a bug, since the conditions should be checked before checking for the uniqueness of the keys. (the result would be only one of the items needs to be executed).

Upvotes: 2

Maria Ines Parnisari
Maria Ines Parnisari

Reputation: 17506

The last two operations (Put & Delete) in TransactItems point to the same object:

 "Item": {
            "name":{
               "S":"700e4d492d86284ebf48a"
            }
         },

Upvotes: 0

Related Questions