Fix handling of UpdateBehavior.WRITE_IF_NOT_EXISTS on @DynamoDbAutoGeneratedUuid #6391
+348
−53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Fixed the behavior of the
@DynamoDbAutoGeneratedUuid
annotation in combination with@DynamoDbUpdateBehavior(UpdateBehavior.WRITE_IF_NOT_EXISTS)
.Previously, a new UUID was generated even when the attribute already had a value. With this change:
UUID.randomUUID()
).WRITE_IF_NOT_EXISTS
, existing values in DynamoDB are preserved using theif_not_exists(...)
expression.This ensures that UUIDs are only generated once for attributes tagged with
WRITE_IF_NOT_EXISTS
and remain stable across subsequent updates.Important Note
String
attribute.@DynamoDbAutoGeneratedKey
(implementation added with this PR) , this extension does not enforce PK/SK or index-only usage — it supports non-key attributes.putItem
, the entire item is always replaced, so if the field is absent, a new UUID will still be generated, even withWRITE_IF_NOT_EXISTS
.Motivation and Context
#5703
This bug fix improves consistency with the documented semantics of
WRITE_IF_NOT_EXISTS
and matches user expectations.Modifications
AutoGeneratedUuidExtension
to only generate UUIDs if the attribute is missing or empty.WRITE_IF_NOT_EXISTS
.AutoGeneratedUuidExtensionTest
and functional tests inAutoGeneratedUuidRecordTest
to verify:WRITE_ALWAYS
vs.WRITE_IF_NOT_EXISTS
.Testing
putItem
andupdateItem
.Test Coverage Checklist
Types of changes
Checklist
mvn install
succeedsscripts/new-change
script and following the instructions. Commit the new file created by the script in.changes/next-release
with your changes.License