UpdateItemEnhancedRequest for null version number with `ignoreNulls(true)` results into ConditionalCheckFailedException
See original GitHub issueDescribe the issue
When we use ignoreNulls(true)
feature while doing table.updateItem
understanding that it will ignore all null fields to update it in db. But it looks like it’s not working as expected for dynamo db version field, when my object contain all required fields like primary hash key, and sort key and version number as null, it’s throwing ConditionalCheckFailedException
.
Steps to Reproduce
Where version number field is declared as below.
@Getter(onMethod_ = {@DynamoDbVersionAttribute})
private Long version;
customDynamoDbBeanObject.version(null);
dynamoDbTable.updateItem(UpdateItemEnhancedRequest.builder(CustomDynamoDbBean.class)
.item(customDynamoDbBeanObject)
.ignoreNulls(true)
.build());
Current Behavior
It’s throwing ConditionalCheckFailedException
.
Your Environment
- AWS Java SDK version used: AwsJavaSdk-DynamoDb-Enhanced = 2.0;
- JDK version used: JDK8 = 1.0;
- Operating System and version: Linux
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
UpdateItemEnhancedRequest.Builder (AWS SDK for Java
By default, the value is false. If set to true, any null values in the Java object will be ignored and not be...
Read more >Optimistic locking with version number - Amazon DynamoDB
Optimistic locking is a strategy to ensure that the client-side item that you are updating (or deleting) is the same as the item...
Read more >Update specific attribute using UpdateItemEnhancedRequest ...
The UpdateItemEnhancedRequest class has an ignoreNulls attribute that will exclude all null attributes from the update.
Read more >UpdateItemEnhancedRequest.Builder<T> - DynamoDB
Sets if the update operation should ignore attributes with null values. By default, the value is false. If set to true, any null...
Read more >Optimistic Locking with the DynamoDB Mapper - Jia Hao
Saving POJOs to DynamoDB with a non-null version when it does not exist will result in a conditional check failed exception; Irregardless of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @debora-ito, you probably want to tag @onkar27 instead of me.
@onkar27 I don’t think version can be null by definition, once you start using it.
The idea of having a version attribute is to make sure the version number on the server side has not changed since you retrieved the item. If the version does not match it means that the item was modified and you have a stale version.
Specifying version = null and say to ignore it when you try to update the item defeats the purpose of optimistic locking. You should provide a version number before updating an item. So getting a
ConditionalCheckFailedException
is expected in this case. Does it make sense?