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

The Enhanced DynamoDB updateBehavior tag doesn't work when the attributename contains a dash #2087

Closed
bramvanswalm opened this issue Oct 13, 2020 · 2 comments · Fixed by #2100
Labels
bug This issue is a bug. dynamodb-enhanced

Comments

@bramvanswalm
Copy link

bramvanswalm commented Oct 13, 2020

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
@bramvanswalm bramvanswalm added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Oct 13, 2020
@bramvanswalm
Copy link
Author

I can create a PR to fix the bug if you want.

@bmaizels
Copy link
Contributor

@bramvanswalm Thank you, great catch! Should be all fixed now.

aws-sdk-java-automation added a commit that referenced this issue Jul 8, 2022
…32e5dc5d1

Pull request: release <- staging/e3055947-7c4a-47e8-af6a-a0432e5dc5d1
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. dynamodb-enhanced
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants