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

ExpressionAttributeValues is incorrectly present when conditions are used #51

Closed
terrbear opened this issue May 20, 2020 · 2 comments
Closed
Labels
bug Something isn't working

Comments

@terrbear
Copy link
Contributor

Writing something like:

  const params = MyEntity.putParams(network, {
    conditions: [
      { attr: "PK", exists: false },
      { attr: "SK", exists: false }
    ]
  });

Results in an ExpressionAttributeValues: {}, which AWS rejects.

Workaround is to add:
delete params.ExpressionAttributeValues;

If you know they're empty.

@jeremydaly jeremydaly added the bug Something isn't working label May 25, 2020
@RavyuS
Copy link

RavyuS commented May 31, 2020

expressionBuilder is referenced putParams (as parseConditions in Entity.js:755). It returns an empty values object by default, which is later assigned to ExpressionAttributeValues.

So exists and other functions will result in the EmptyExpressionAttributeValues error you see. My relatively primitive workaround replaces Entity.js:795 with

!isEmpty(ExpressionAttributeValues) ? { ExpressionAttributeValues } : null,

Where isEmpty is a custom function (whatever I found on google) that checks for empty objects.

Of course this is pretty dumb, but I thought of just sharing this!

Nemo64 added a commit to Nemo64/dynamodb-toolbox that referenced this issue Jul 5, 2020
…lbox#51)

When only using conditions like {attr: 'id', exists: true}
there aren't any attribute values created but the option is still passed.
The DynamoDB api sees this as a ValidationException.
@jeremydaly
Copy link
Collaborator

Thanks @RavyuS and @Nemo62. The pull request only fixed put, but the same issue was possible with the delete method as well. I've added a fix that puts an isEmpty function in the utils and then uses that to check the parameters when they are assembled. Thanks for everyone's input on this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants