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

Extend put_item to allow conditions #3

Merged
merged 3 commits into from
May 24, 2018

Conversation

blt
Copy link
Contributor

@blt blt commented May 23, 2018

This pull request extends the put_item call to allow for ConditionExpression and related attributes in said call. This allows for compare-and-swap operations, which is tested for explicitly in the darcy_test suite.

Resolves #2

Brian L. Troutwine added 3 commits May 22, 2018 13:40
This commit introduces ConditionExpression, ExpressionAttributeNames
and ExpressionAttributeValues as options to a new put_item/4. Tests
for the same have been introduced though, curiously, they fail against
DynamoDBLocal with the following error:

```
Failures:

  1) darcy_test:cas_test/0
     Failure/Error: {error,
                        {badmatch,
                            {error,
                                {{<<"com.amazonaws.dynamodb.v20120810#InternalFailure">>,
                                  <<"The request processing has failed because of an unknown error, exception or failure.">>},
                                 [500,
                                  [{<<"Content-Type">>,
                                    <<"application/x-amz-json-1.0">>},
                                   {<<"x-amzn-RequestId">>,
                                    <<"6cb7bb75-03aa-483d-9e00-430b4b288527">>},
                                   {<<"Content-Length">>,<<"158">>},
                                   {<<"Server">>,
                                    <<"Jetty(8.1.12.v20130726)">>}]]}}},
                        [{darcy_test,cas_test,0,
                             [{file,
                                  "/Users/briantroutwine/projects/com/github/darcy/_build/test/lib/darcy/test/darcy_test.erl"},
                              {line,102}]}]}
```

I'm kinda stumped. The resulting payload doesn't appear, to me,
to be invalid but it must be, based on the way DynamoDBLocal has
responded.

Signed-off-by: Brian L. Troutwine <blt@postmates.com>
Okay, well, I've gotten to the point of a new error being produced:

```
Failures:

  1) darcy_test:cas_test/0
     Failure/Error: {error,
                        {badmatch,
                            {error,
                                {{<<"com.amazon.coral.validate#ValidationException">>,
                                  <<"ExpressionAttributeNames can only be specified when using expressions">>},
                                 [400,
                                  [{<<"Content-Type">>,
                                    <<"application/x-amz-json-1.0">>},
                                   {<<"x-amzn-RequestId">>,
                                    <<"50b60fe0-8b64-4fa7-9151-1dde8490b566">>},
                                   {<<"Content-Length">>,<<"140">>},
                                   {<<"Server">>,
                                    <<"Jetty(8.1.12.v20130726)">>}]]}}},
                        [{darcy_test,cas_test,0,
                             [{file,
                                  "/Users/briantroutwine/projects/com/github/darcy/_build/test/lib/darcy/test/darcy_test.erl"},
                              {line,103}]}]}
```

I'll try this code against real DynamoDB tomorrow to confirm that
I get the same failure. My hope is it's a bug against the local
version.

Signed-off-by: Brian L. Troutwine <blt@postmates.com>
Okay! Turns out, I was trying to send "ConditionalExpression" to
Dynamo when in fact the correct incantation was "ConditionExpression".
Now that this is resolved, I've confirmed that CAS works as intended
by testing.

Signed-off-by: Brian L. Troutwine <blt@postmates.com>
@jadeallenx
Copy link
Owner

I'll take a look tomorrow. Thanks!

@jadeallenx jadeallenx merged commit 4652315 into jadeallenx:master May 24, 2018
@jadeallenx
Copy link
Owner

Thanks for the PR! Great work. Happy to include it! I'll tag a new release and push it to hex shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants