fix(dynamodb): compare numeric key attributes by value in UpdateItem (#5837)

* fix(dynamodb): compare numeric key attributes by value in UpdateItem

UpdateItem and the TransactWriteItems Update path rejected a request
whose key carried an equivalent but differently written number, such as
a sort key of {"N":"1700000000.0"} against a stored {"N":"1700000000"},
with "Cannot update attribute timestamp. This attribute is part of the
key". Stored numbers are normalized on write, and the key-modification
check compared AttributeValue JSON nodes structurally.

The check now uses attributeValuesEqual, which requires matching types
and compares N by numeric value, as DynamoDB does. The item lookup
already treated these keys as the same item.

* fix(dynamodb): reject key attribute values with more than one type member in UpdateItem

Comparing key attributes with attributeValuesEqual matches on the first
type member the two values share, so an UpdateExpression that set a key
attribute to a value carrying an extra type member passed the key check
and the malformed key was stored. The request key is already validated
for shape and schema type when the item key is built, so checking that
the updated value has exactly one type member is enough for the
comparison to imply a matching schema type.
This commit is contained in:
Tyler Webb authored and GitHub committed 2026-10-16 19:46:44 -04:00
1 parent 3db18d58a5
commit ad57ac837f
2 files changed
+144 -2

No files matched your search

@@ -2082,7 +2082,10 @@ public class DynamoDbService {
String pkName = table.getPartitionKeyName();
JsonNode origPk = key.get(pkName);
JsonNode newPk = item.get(pkName);
if (origPk != null && newPk != null && !origPk.equals(newPk)) {
if (newPk != null) {
validateAttributeValueShape(newPk);
}
if (origPk != null && newPk != null && !attributeValuesEqual(origPk, newPk)) {
throw new AwsException("ValidationException",
"One or more parameter values were invalid: Cannot update attribute " + pkName
+ ". This attribute is part of the key", 400);
@@ -2091,7 +2094,10 @@ public class DynamoDbService {
if (skName != null) {
JsonNode origSk = key.get(skName);
JsonNode newSk = item.get(skName);
if (origSk != null && newSk != null && !origSk.equals(newSk)) {
if (newSk != null) {
validateAttributeValueShape(newSk);
}
if (origSk != null && newSk != null && !attributeValuesEqual(origSk, newSk)) {
throw new AwsException("ValidationException",
"One or more parameter values were invalid: Cannot update attribute " + skName
+ ". This attribute is part of the key", 400);