clarkie / dynogels

DynamoDB data mapper for node.js. Originally forked from https://github.com/ryanfitz/vogels
Other
490 stars 110 forks source link

On table.create, the ConditionExpression isn't merged correctly #7

Closed clarkie closed 6 years ago

clarkie commented 8 years ago

Assume that it is necessary to specify a Condition Expression for create and also the option overwrite:

var params = {};
params.ConditionExpression = '#n <> :x';
params.ExpressionAttributeNames = {'#n' : 'name'};
params.ExpressionAttributeValues = {':x' : 'Kurt Warner'};
params.overwrite = false;

User.create({id : 123, name : 'Kurt Warner' }, params, function (error, acc) { ... });

Then, ConditionExpression is not set correctly because of the following line in file table.js:

189 params = _.merge({}, params, options);`

The merge overwrites the ConditionExpression and instead of "(id <> :id) AND #n <> :x, you get #n <> :x. The lodash merge doesn't merge correctly the ConfitionExpression. And the following error is issue by AWS SDK:

'Error: ValidationException: Value provided in ExpressionAttributeNames unused in expressions: keys: {#id}'.
jkav77 commented 7 years ago

I encountered this same problem working on #39. _.merge doesn't work on this because the two values are strings (instead of objects). I will look at what I did on #39 and see if it can solve this too.

jkav77 commented 7 years ago

If you set { overwrite: false }, then .create() should only work if the item does not exist. But how can you have a ConditionExpression if the item doesn't exist? I'm not sure I understand the reason for specifying overwrite to false for a conditional .create().

jkav77 commented 6 years ago

@clarkie what do you want to do with this one? I would like to close the old issues that aren't getting attention.

jkav77 commented 6 years ago

Closing as stale.