Skip to content

Commit

Permalink
fix ddb crash if condition produces empty value
Browse files Browse the repository at this point in the history
  • Loading branch information
fogfish committed Oct 31, 2020
1 parent a8f61c2 commit ac085dd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion constrain.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func (e ElemIs) Exists() Config {
/*
NotExists attribute constrain
name.Exists(x) ⟼ attribute_not_exists(name)
name.NotExists(x) ⟼ attribute_not_exists(name)
*/
func (e ElemIs) NotExists() Config {
return e.constrain("attribute_not_exists")
Expand Down
14 changes: 10 additions & 4 deletions ddb.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ func (dynamo DB) Put(entity curie.Thing, config ...Config) (err error) {
TableName: dynamo.table,
}
if len(config) > 0 {
req.ExpressionAttributeValues = map[string]*dynamodb.AttributeValue{}
config[0](&req.ConditionExpression, req.ExpressionAttributeValues)
values := map[string]*dynamodb.AttributeValue{}
config[0](&req.ConditionExpression, values)
if len(values) > 0 {
req.ExpressionAttributeValues = values
}
}
_, err = dynamo.db.PutItem(req)
if err != nil {
Expand Down Expand Up @@ -119,8 +122,11 @@ func (dynamo DB) Remove(entity curie.Thing, config ...Config) (err error) {
TableName: dynamo.table,
}
if len(config) > 0 {
req.ExpressionAttributeValues = map[string]*dynamodb.AttributeValue{}
config[0](&req.ConditionExpression, req.ExpressionAttributeValues)
values := map[string]*dynamodb.AttributeValue{}
config[0](&req.ConditionExpression, values)
if len(values) > 0 {
req.ExpressionAttributeValues = values
}
}

_, err = dynamo.db.DeleteItem(req)
Expand Down

0 comments on commit ac085dd

Please sign in to comment.