Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
onkar27 opened this issue Aug 12, 2020 · 5 comments
Labels
documentation This is a problem with documentation. p3 This is a minor priority issue

Comments

@onkar27
Copy link

onkar27 commented Aug 12, 2020

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
@onkar27 onkar27 added guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Aug 12, 2020
@debora-ito
Copy link
Member

debora-ito commented Aug 13, 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?

@debora-ito debora-ito added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. and removed needs-triage This issue or PR still needs to be triaged. labels Aug 13, 2020
@onkar
Copy link

onkar commented Aug 14, 2020

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

@debora-ito
Copy link
Member

Sorry for the confusion 😬

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Aug 14, 2020
@debora-ito debora-ito added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Aug 14, 2020
@onkar27
Copy link
Author

onkar27 commented Aug 14, 2020

@debora-ito Thanks for reply, yeah I understand it when I'm reading for optimistic locking in dynamoDB. I think in the documentation of ignoreNulls(true) here, we should have it mentioned for version fields ignoreNulls feature doesn't apply.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Aug 14, 2020
@debora-ito debora-ito added documentation This is a problem with documentation. and removed guidance Question that needs advice or information. labels Sep 9, 2020
@bufistov
Copy link

You can disable "Versioning" extension in mapper to bypass locking:

DynamoDbEnhancedClient.builder().dynamoDbClient(DynamoDbClient.create())
.extensions(Collections.emptyList()) // Disable version locking
.build()

aws-sdk-java-automation pushed a commit that referenced this issue Apr 7, 2022
@yasminetalby yasminetalby added the p3 This is a minor priority issue label Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation This is a problem with documentation. p3 This is a minor priority issue
Projects
None yet
Development

No branches or pull requests

5 participants