Fix additionalAttributeNames in UpdateItemCodableInput by mapping key array #673
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#671 has introduced a new method to initialize UpdateItemCodableInput, but it has introduced an issue.
Consider the following code:
The intention of the previous code is to update the item only when the key exists and when the record to update has the same createdAt and updatedAt data stored in DynamoDB. The update will change updatedAt with a new timestamp. In this way a client that doesn't have the same item cannot update the DynamoDB table and is forced to read the item before an update. (Optimistic locking)
But it leads to the following exception:
To fix the issue the code has be changed to include only the key in additionalAttributeNames and avoiding to add attributes that are not used.
The client code can be fixed by using:
In the Unit Tests, the optimistic locking has been tested using
id
as key andage
as condition to validate the record.An alternative solution could be to add an explicit parameter to additionalAttributeNames.