awslabs / dynamodb-data-mapper-js

A schema-based data mapper for Amazon DynamoDB.
https://awslabs.github.io/dynamodb-data-mapper-js/
Apache License 2.0
817 stars 106 forks source link

executeUpdateExpression creates new row if passed in key does not exist #179

Open Jamesargy6 opened 4 years ago

Jamesargy6 commented 4 years ago

I'm trying to run a custom update on my table, but I'm running into unexpected behavior if there is no row with the key I specify

const toUpdate = new MyModel()
toUpdate.key = 'nonexistent_key'

const updateExp = new UpdateExpression()
updateExp.set('prop_a','a_value')
updateExp.remove('prob_b')
updateExp.set('prop_c', 'c_value')
const updated = await this.mapper.executeUpdateExpression(updateExp, toUpdate, MyModel)

The code above produces a new row in my database with the key 'nonexistent_key', But I would expect to get an ItemNotFoundException like I would if I were just using update.

I know I can probably add a ConditionExpression to this call to make sure the thing I'm trying to update exists, but that seems to defeat the purpose of passing in the toUpdate parameter. Is there some configuration I can pass in to force an error, am I missing something, or is this really expected behavior?

Jamesargy6 commented 4 years ago

Actually, adding a ConditionExpression doesn't help either.