'DynamoDB update duplicates records in List field

I'm performing an update (or create if it doesn't exist) on a DynamoDB table with the following params:

{
    "TableName": "TableName",
    "Key": {
        "PartitionKey": "TEST#",
        "SortKey": "SK#123456"
    },
    "UpdateExpression": "set WaterTests = list_append(if_not_exists(WaterTests, :empty_list), :waterTestValues),  MakeModel = :mm, Version = :v, Username = :username",
    "ExpressionAttributeValues": {
        ":waterTestValues": [
            {
                "DateTest": "2022-03-29T09:40:50.985Z",
                "IsValid": true,
                "S3Path": "sample/s3/path"
            }
        ],
        ":v": "v1",
        ":mm": "No Make Model",
        ":username": "[email protected]",
        ":empty_list": []
    },
    "ReturnValues": "UPDATED_NEW"
}

It invariably results in the following (for a non existing record, unique HK+SK):

{
    "PartitionKey": "SESSION#",
    "SortKey": "USER#[email protected]#999fe1b3-0b59-4a41-9eef-37d433566af0",
    "WifiTests": [
    {
    "DateTest": "2022-03-29T09:40:50.985Z",
    "IsValid": true,
    "S3Path": "sample/s3/path"
    },
    {
    "DateTest": "2022-03-29T09:40:50.985Z",
    "IsValid": true,
    "S3Path": "sample/s3/path"
    }
    ]...

I'm using a standard update call as follows:

await docClient.update(params, function (err, data) {
        if (err) console.log(err);
        else console.log(data);
    }).promise();

I have no clue on why the duplication always happens.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source