question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UpdateItemEnhancedRequest for null version number with `ignoreNulls(true)` results into ConditionalCheckFailedException

See original GitHub issue

Describe 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:open
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
onkarcommented, Aug 14, 2020

Hi @debora-ito, you probably want to tag @onkar27 instead of me.

1reaction
debora-itocommented, Aug 14, 2020

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found