I have the next error in my DynamoDB request:
{
"__type":"com.amazon.coral.validate#ValidationException",
"message":"Invalid UpdateExpression:
Two document paths overlap with each other; must remove or rewrite one of
these paths; path one: [cart, items, [1], vat-item], path two: [cart, items]"
}
I am using the next expression:
"UpdateExpression":"SET
cart.#listName[0].quantity = cart.#listName[0].quantity + :quantity1,
cart.#listName[0].price = :price1,
cart.#listName[0].#vatItem = :vatItem1,
cart.#listName[1].quantity = cart.#listName[1].quantity + :quantity2,
cart.#listName[1].price = :price2,
cart.#listName[1].#vatItem = :vatItem2,
cart.#listName = list_append (cart.#listName, :jsonObject)"}
Is there any hack to do work fine "set elements and add anothers"?
I found this question on stackoverflow but this guy is trying to do delete and set, and me only set.
Added an MRE in python for those willing to try at home:
import boto3
TABLE_NAME = "pk-only"
TABLE_RESOURCE = boto3.resource("dynamodb").Table(TABLE_NAME)
DDB_CLIENT = boto3.client("dynamodb")
def create_table():
DDB_CLIENT.create_table(
AttributeDefinitions=[{"AttributeName": "PK", "AttributeType": "S"}],
TableName=TABLE_NAME,
KeySchema=[{"AttributeName": "PK", "KeyType": "HASH"}],
BillingMode="PAY_PER_REQUEST"
)
def add_sample_item():
TABLE_RESOURCE.put_item(
Item={
"PK": "append_and_update",
"list": [
{
"value": "a"
}
]
}
)
def update():
TABLE_RESOURCE.update_item(
Key={
"PK": "append_and_update"
},
UpdateExpression="SET #l = list_append(#l, :newItem), #l[0].#val = :newVal",
ExpressionAttributeNames={
"#l": "list",
"#val": "value",
},
ExpressionAttributeValues={
":newVal": "b",
":newItem": {"M": {"value": {"S": "c"}}}
}
)
def main():
# create_table()
add_sample_item()
update()
if __name__ == "__main__":
main()