Skip to content

Conversation

@zoewangg
Copy link
Contributor

@zoewangg zoewangg commented Oct 31, 2025

Motivation and Context

Fixes #3279

When using @DynamoDbVersionAttribute with attribute names containing special characters (hyphens, dots, colons, etc.), DynamoDB operations fail with:

DynamoDbException: ExpressionAttributeValues contains invalid key: Syntax error; key: ":old_my-version-attribute_value"

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_MAPPER to use cleanAttributeName() when generating expression value placeholder keys. This ensures special characters in version attribute names are replaced with underscores, making the placeholders valid

Changed:

// Before
private static final Function<String, String> VERSIONED_RECORD_EXPRESSION_VALUE_KEY_MAPPER =
    key -> ":old_" + key + "_value";

// After
private static final Function<String, String> VERSIONED_RECORD_EXPRESSION_VALUE_KEY_MAPPER =
    key -> ":old_" + cleanAttributeName(key) + "_value";

Note that this will not introduce breaking behavior as it only affects the Bug Case

  • Attribute names without special characters generate the same placeholder as before:
    • "version" → :old_version_value (unchanged)
  • Attribute names with special characters now work instead of failing:
    • "my-version" → :old_my_version_value (was throwing exception before)

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

…names containing special characters (hyphens, dots, colons, etc.) when using optimistic locking. Previously, these would fail with an ExpressionAttributeValues contains invalid key error.
@zoewangg zoewangg requested a review from a team as a code owner October 31, 2025 23:01
@zoewangg zoewangg added the no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required label Oct 31, 2025
@zoewangg zoewangg enabled auto-merge November 3, 2025 18:33
@sonarqubecloud
Copy link

sonarqubecloud bot commented Nov 3, 2025

@zoewangg zoewangg added this pull request to the merge queue Nov 3, 2025
Merged via the queue into master with commit 80356a2 Nov 3, 2025
39 checks passed
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DynamoDb Enhanced - VersionedRecordExtension doesn't properly handle attribute names with special characters.

2 participants