aws-sdk-java-v2
aws-sdk-java-v2 copied to clipboard
Optimistic locking VersionedRecordExtension fails when field is called _version instead of version
Describe the bug
For optimistic locking when using the sdk v2 dynamodb enhanced client I specified
@DynamoDbVersionAttribute
public Integer get_version() { return _version; }
public void set_version(Integer version) { this._version = version;}
in my model because I want the version field which gets stored in dynamo be named _version instead of version. This is needed for integration with amplify DataStore.
It all works fine when the field is called version. If I instead call it version I get Invalid ConditionExpression: Syntax error; token: "", near: "(_version" (Service: DynamoDb, Status Code: 400, Request ID: 01UGIGDVS0SBSRTG57TR09FV8NVV4KQNSO5AEMVJF66Q9ASUAAJG, Extended Request ID: null)
Expected behavior
Let me specify the name for the optimistic locking/ VersionedRecordExtension field.
Current behavior
I get Invalid ConditionExpression: Syntax error; token: "_", near: "(_version" (Service: DynamoDb, Status Code: 400, Request ID: 01UGIGDVS0SBSRTG57TR09FV8NVV4KQNSO5AEMVJF66Q9ASUAAJG, Extended Request ID: null)
error Message.
Steps to Reproduce
In the model class, specify
@DynamoDbVersionAttribute
public Integer get_version() { return _version; }
public void set_version(Integer version) { this._version = version;}
for the Optimistic locking / VersionedRecordExtension field
Possible Solution
No response
Context
I want to use optimistic locking when writing from my java lambdas to dynamo and I need to name this field _version for integration with amplify DataStore
AWS Java SDK version used
software.amazon.awssdk:bom:2.17.40
JDK version used
11
Operating System and version
macOS Monterey
Hi @marcelweigle thank you for reaching out.
Underscore (_) is probably a special character that requires some handling. Using Expression Attribute Names will likely fix this.
Related to https://github.com/aws/aws-sdk-java-v2/issues/2507.
I also encountered this problem while migrating from the V1 SDK. My class field name is version
but I was using @DynamoDBVersionAttribute(attributeName = "_version")
to change it. In version V2, if I'm adding @DynamoDbAttribute(value = "_version")
to the getter of the version field then the putItem()
method fails with the same error mentioned by @marcelweigle above.
@debora-ito , do you have any estimation on how long would it take for a fix to be released for this?
@debora-ito this seems like an extremely straightforward fix (and I provided a code example where this is properly handled in a different class in the duplicate issue I opened) but this issue has been open for 6 months. Any plans to implement a fix?
Edit: In fact the related issue linked above has been open for 13 months. These bugs block anyone using the V1 API from upgrading who use special characters or reserved words in their attribute names.
A fix was released in Java SDK version 2.17.233.
Please let us know if you have any follow-up questions.