Skip to content

Commit 80356a2

Browse files
authored
The DynamoDB Enhanced Client now correctly handles version attribute names containing special characters (hyphens, dots, colons, etc.) when using optimistic locking. Previously, these would fail with an ExpressionAttributeValues contains invalid key error. (#6538)
1 parent bb84827 commit 80356a2

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "DynamoDB Enhanced Client",
4+
"contributor": "",
5+
"description": "The DynamoDB Enhanced Client now properly sanitizes version attribute names when building conditional expressions for optimistic locking. Version attributes with special characters in their names will now work correctly. See [#3279](https://github.com/aws/aws-sdk-java-v2/issues/3279)"
6+
}

services-custom/dynamodb-enhanced/src/main/java/software/amazon/awssdk/enhanced/dynamodb/extensions/VersionedRecordExtension.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package software.amazon.awssdk.enhanced.dynamodb.extensions;
1717

18+
import static software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils.cleanAttributeName;
1819
import static software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils.isNullAttributeValue;
1920
import static software.amazon.awssdk.enhanced.dynamodb.internal.EnhancedClientUtils.keyRef;
2021

@@ -58,7 +59,8 @@
5859
@SdkPublicApi
5960
@ThreadSafe
6061
public final class VersionedRecordExtension implements DynamoDbEnhancedClientExtension {
61-
private static final Function<String, String> VERSIONED_RECORD_EXPRESSION_VALUE_KEY_MAPPER = key -> ":old_" + key + "_value";
62+
private static final Function<String, String> VERSIONED_RECORD_EXPRESSION_VALUE_KEY_MAPPER =
63+
key -> ":old_" + cleanAttributeName(key) + "_value";
6264
private static final String CUSTOM_METADATA_KEY = "VersionedRecordExtension:VersionAttribute";
6365
private static final VersionAttribute VERSION_ATTRIBUTE = new VersionAttribute();
6466

services-custom/dynamodb-enhanced/src/test/java/software/amazon/awssdk/enhanced/dynamodb/functionaltests/VersionedRecordWithSpecialCharactersTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public int hashCode() {
9797
.addAttribute(String.class, a -> a.name("_attribute")
9898
.getter(Record::get_attribute)
9999
.setter(Record::set_attribute))
100-
.addAttribute(Integer.class, a -> a.name("_version")
100+
.addAttribute(Integer.class, a -> a.name("_my-:.version")
101101
.getter(Record::get_version)
102102
.setter(Record::set_version)
103103
.tags(versionAttribute()))

0 commit comments

Comments
 (0)