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

DynamoDbIgnoreNulls Doesn't Work On Most Writes #2938

Closed
nicksbyman opened this issue Dec 27, 2021 · 2 comments
Closed

DynamoDbIgnoreNulls Doesn't Work On Most Writes #2938

nicksbyman opened this issue Dec 27, 2021 · 2 comments
Labels
bug This issue is a bug. closed-for-staleness dynamodb-enhanced response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.

Comments

@nicksbyman
Copy link

nicksbyman commented Dec 27, 2021

Describe the bug

When a user performs dynamo writes with the enhanced aws client with transactWriteItems or putItems, "DynamoDbIgnoreNulls" doesn't cause the write to ignore null attributes on the record being written.

That is, from #2303 it sounds like using the annotation should work fluidly like the other annotations, but because DefaultDynamoDbEnhancedClient.java just makes a TransactWriteItemsEnhancedRequest and sends it to dynamo. It doesn't look at the record being written to see if certain fields shouldn't overwrite existing fields with null.

Let me know if user error! But certainly feels like this annotation does not work fluidly with this usage of the enhanced client. I'm forced to set ignoreNulls manually on my own instead of relying on the annotation.

Expected behavior

"DynamoDbIgnoreNulls" should ignore null attributes on the record being written

Current behavior

"DynamoDbIgnoreNulls" doesn't ignore null attributes on the record being written

Steps to Reproduce

@DynamoDbBean
@Setter
public class MyDynamoBean {
     @DynamoDbIgnoreNulls
     private final String myAttribute;
  
}

public void myWriteMethod(MyDynamoBean myBean) {
    myClient.transactWriteItems(myConsumer -> {
          myConsumer.addUpdateItem(myTable, myBean);
    }

    myBean.setMyAttribute(null);
   
    myClient.transactWriteItems(myConsumer -> {
          myConsumer.addUpdateItem(myTable, myBean);
    }
}

In the above, the second write deletes the pre-existing value of myAttribute.

Possible Solution

Maybe call itemToMap() somewhere around transactWriteItems? That seems how we get the information from the bean based on the annotations. Based on #2303

Context

No response

AWS Java SDK version used

2.17.91

JDK version used

11.0.12

Operating System and version

Mac Big Sur, 11.6.1

@nicksbyman nicksbyman added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 27, 2021
@debora-ito
Copy link
Member

debora-ito commented Jan 13, 2022

@nicksbyman the @DynamoDbIgnoreNulls annotation should be added on the getter or setter of the attribute (and not on the attribute itself). Maybe that's the issue?

@debora-ito debora-ito added bug This issue is a bug. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. dynamodb-enhanced and removed bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Jan 13, 2022
@github-actions
Copy link

It looks like this issue has not been active for more than five days. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please add a comment to prevent automatic closure, or if the issue is already closed please feel free to reopen it.

@github-actions github-actions bot added closing-soon This issue will close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will close in 4 days unless further comments are made. labels Jan 19, 2022
aws-sdk-java-automation added a commit that referenced this issue Mar 28, 2024
…51dc12f77

Pull request: release <- staging/dd7c8a0e-7c3f-4f67-90ae-cfd51dc12f77
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. closed-for-staleness dynamodb-enhanced response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days.
Projects
None yet
Development

No branches or pull requests

2 participants