0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

motoを使用したDynamoDBのトランザクション処理でThe "SET" section can only be used once in an update expressionが発生した時の対処

Posted at

以下のような、オペレーションがUpdateのDynamoDB書き込み処理があるとします。

sample.py
import boto3
from boto3.dynamodb.types import TypeSerializer

client = boto3.client("dynamodb")
serializer = TypeSerializer()

options = {
    "TransactItems": [
        {
            "Update": {
                "TableName": "test-table",
                "Key": {"pk": serializer.serialize("test")},
                "UpdateExpression": "SET test = :test",
                "ExpressionAttributeValues": {":test": serializer.serialize("xxx")},
            }
        }
    ]
}

client.transact_write_items(**options)

motoでDynamoDBをモック化し、上記ソースコードのテストを実行すると・・・

The "SET" section can only be used once in an update expression

エラーが出ました。
ちなみにオペレーションがPut、Deleteの時は特にエラーが出ませんでした。

解消法

motoのバージョンを5.0.11以上にアップデートする。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?