Fix VersionedRecordExtension to sanitize attribute names in expression value keys #6538
+10
−2
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.



Motivation and Context
Fixes #3279
When using @DynamoDbVersionAttribute with attribute names containing special characters (hyphens, dots, colons, etc.), DynamoDB operations fail with:
The issue occurs because VersionedRecordExtension generates expression value placeholder keys directly from the attribute name without sanitizing special characters, which are not allowed in DynamoDB
expression value placeholders.
Modifications
Updated
VERSIONED_RECORD_EXPRESSION_VALUE_KEY_MAPPERto use cleanAttributeName() when generating expression value placeholder keys. This ensures special characters in version attribute names are replaced with underscores, making the placeholders validChanged:
Note that this will not introduce breaking behavior as it only affects the Bug Case
Testing
Updated existing test case to use an attribute key name with invalid character
Types of changes
• [x] Bug fix (non-breaking change which fixes an issue)
• [ ] New feature (non-breaking change which adds functionality)
Checklist
• [x] I have read the CONTRIBUTING document
• [x] Local run of mvn install succeeds
• [x] My code follows the code style of this project
• [ ] My change requires a change to the Javadoc documentation
• [ ] I have updated the Javadoc documentation accordingly
• [x] I have added tests to cover my changes
• [x] All new and existing tests passed
• [ ] I have added a changelog entry. Adding a new entry must be accomplished by running the scripts/new-change script and following the instructions. Commit the new file created by the script in
.changes/next-release with your changes.
• [ ] My change is to implement 1.11 parity feature and I have updated LaunchChangelog
License
• [x] I confirm that this pull request can be released under the Apache 2 license