Closed
Description
Describe the bug
When using the updateBehavior tag introduced in PR on an attribute that contains a dash, a DynamoDbException
is thrown.
Expected Behavior
The attributename used in the if_not_exists should use a cleaned attribute name just like the other expression values.
Current Behavior
An exception is thrown:
software.amazon.awssdk.services.dynamodb.model.DynamoDbException: Invalid UpdateExpression: Syntax error; token: "-"
Steps to Reproduce
Create a StaticTableSchema
with an attribute that contains a dash in it's name and has the updateBehavior(UpdateBehavior.WRITE_IF_NOT_EXISTS)
tag.
.addAttribute(EnhancedType.listOf(RelatedParty.class), a -> a.name("Abc-Def")
.getter(DbExpenseTransaction::getAbcDef)
.setter(DbExpenseTransaction::setAbcDef)
.tags(updateBehavior(UpdateBehavior.WRITE_IF_NOT_EXISTS)))
Possible Solution
In the UpdateItemOperation
class, the following code:
private static final Function<String, String> CONDITIONAL_UPDATE_MAPPER =
key -> "if_not_exists(" + key + ", " + EXPRESSION_VALUE_KEY_MAPPER.apply(key) + ")";
should also be using the EXPRESSION_KEY_MAPPER
like this:
private static final Function<String, String> CONDITIONAL_UPDATE_MAPPER =
key -> "if_not_exists(" + EXPRESSION_KEY_MAPPER.apply(key) + ", " + EXPRESSION_VALUE_KEY_MAPPER.apply(key) + ")";
Your Environment
- AWS Java SDK version used: 2.15.7
- JDK version used: 11
- Operating System and version: macOS 10.15.7