fix(dynamodb): name the partition key in a PartiQL INSERT's own condition (#7381)

This commit is contained in:
Hector Ventura authored and GitHub committed 2026-11-03 07:50:52 -04:00
1 parent eaa553cf7a
commit 4933126314
2 files changed
+95 -3

No files matched your search

@@ -550,10 +550,11 @@ class DynamoDbPartiQLHandler {
ObjectNode item = mapper.createObjectNode();
stmt.item().forEach((k, v) -> item.set(k, toTypedNode(v)));
ExprAttrNameBuilder ean = new ExprAttrNameBuilder();
String keyIsNew = "attribute_not_exists(" + ean.alias(pkName) + ")";
JsonNode previousItem;
try {
previousItem = service.putItem(stmt.table(), item, "attribute_not_exists(" + pkName + ")",
null, null, region, "NONE");
previousItem = service.putItem(stmt.table(), item, keyIsNew, ean.toNode(mapper), null, region, "NONE");
} catch (ConditionalCheckFailedException e) {
throw new AwsException("DuplicateItemException", "Duplicate primary key exists in table", 400);
}
@@ -674,7 +675,9 @@ class DynamoDbPartiQLHandler {
ObjectNode put = mapper.createObjectNode();
put.put("TableName", ins.table());
put.set("Item", item);
put.put("ConditionExpression", "attribute_not_exists(" + pkName + ")");
ExprAttrNameBuilder ean = new ExprAttrNameBuilder();
put.put("ConditionExpression", "attribute_not_exists(" + ean.alias(pkName) + ")");
put.set("ExpressionAttributeNames", ean.toNode(mapper));
txItem.set("Put", put);
}
case Stmt.Update upd -> {