transactionWrite not working with `UPDATE_SKIP_NULL_ATTRIBUTES`
Describe the bug
I'm trying to use DynamoDB transactions in the following manner ( using Kotlin ) :
val transactionWriteRequest = TransactionWriteRequest()
transactionWriteRequest.addUpdate(node)
mapper.transactionWrite(transactionWriteRequest, dynamoDBMapperConfig)
Where, dynamoDBMapperConfig is defined as :
dynamoDBMapperConfig = DynamoDBMapperConfig.Builder()
.withConsistentReads(DynamoDBMapperConfig.ConsistentReads.CONSISTENT)
.withSaveBehavior(DynamoDBMapperConfig.SaveBehavior.UPDATE_SKIP_NULL_ATTRIBUTES)
.build()
My object looks like :
id : 123
name : xyz
createdAt : null
In my DDB Table, this is stored as
id : 123
name : abc
createdAt : 1636380634908
Expected behavior
The table should've had the following entry :
id : 123
name : xyz
createdAt : 1636380634908
Current behavior
The table rather has :
id : 123
name : abc
createdAt should've been skipped but was removed instead from the table.
Steps to Reproduce
Create an object and insert it into dynamodb table with the following attributes :
id ( PK ) , name, createdAt
Then update the same object with createdAt set as null.
Using the following dependency :
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.12.70</version>
</dependency>
Possible Solution
generateUpdate method ( In DynamoDBMapper.java ) is not considering the fact that UPDATE_SKIP_NULL_ATTRIBUTES was passed as part of config and hence creating a map of null non key values and removing them.
Context
No response
AWS Java SDK version used
1.12.70
JDK version used
11
Operating System and version
macOS Big Sur, 11.6
Apologies for the delay, taking a look.
I think SaveBehavior is not supported in transactionWrite. I'm digging into the code to confirm because the docs don't explicitly say that.
And, of course, immediately after I wrote that comment I found a documentation (DynamoDBMapper link):
This method ignores any SaveBehavior set on the mapper. Whether an object is put or updated is solely determined by the TransactionWriteRequest method called by user while constructing request object. Furthermore, put and update work as if SaveBehavior is set as CLOBBER.
Changing to a Guidance question and marking this to auto-close soon. Add a comment if you have further questions, it will prevent the issue to be auto-closed.
how to sovle the issue ?i don't want to update all the null fields
@mamakancha have you solved this issue? could you share me your solution? thanks
i found a way to work around. just create a DDB mapper POJO class to put the fields that your want to update and the hash fields in it. other field will not be chagned after transactionwrite
@weibian-wyze can you please explain your approach a bit or better if you could share an approach commit. Thanks!