Open
Description
Describe the bug
A ConditionalCheckFailedException
is thrown when updating an item that has a partition key attribute which uses DynamoDbAutoGeneratedUuid
, and a version attribute using DynamoDbVersionAttribute
.
If the DynamoDbAutoGeneratedUuid
annotation is removed (and the partition key is populated manually) the issue doesn't occur.
Expected Behavior
I expected the item update to succeed.
Current Behavior
A ConditionalCheckFailedException
is thrown from the update operation.
Reproduction Steps
Here's the DynamoDbBean
class:
@DynamoDbBean
public class Record {
private String id;
private String content;
private Integer version;
@DynamoDbPartitionKey
@DynamoDbAutoGeneratedUuid
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
@DynamoDbVersionAttribute
public Integer getVersion() {
return version;
}
public void setVersion(Integer version) {
this.version = version;
}
}
And here's the test code which produces the exception:
DynamoDbClient client = DynamoDbClient.create();
DynamoDbEnhancedClient enhancedClient = DynamoDbEnhancedClient.builder()
.extensions(
AutoGeneratedUuidExtension.create(),
VersionedRecordExtension.builder().build()
).build();
DynamoDbTable<Record> table = enhancedClient.table("test_table", TableSchema.fromBean(Record.class));
public void testVersionIncrementedOnUpdate() {
Record newRecord = new Record();
newRecord.setContent("foo");
table.putItem(newRecord);
// The item is in the table, and has a version of 1
Record existingRecord = table.scan().items().stream().findFirst().get();
assertEquals("foo", existingRecord.getContent());
assertEquals(1, existingRecord.getVersion());
existingRecord.setContent("bar");
// Throws ConditionalCheckFailedException
Record updatedRecord = table.updateItem(existingRecord);
assertEquals("bar", updatedRecord.getContent());
assertEquals(2, updatedRecord.getVersion());
}
Possible Solution
No response
Additional Information/Context
Please let me know if this is actually expected behavior, or an unsupported usage of auto-generated UUIDs for partition keys.
AWS Java SDK version used
2.27.1
JDK version used
openjdk 21.0.3 2024-04-16 LTS
Operating System and version
macOS Sonoma 14.5 (23F79)