1

I'm trying to put a condition on the first item on a list, when the list may or may not exist. I am trying to check if the list exists first, but DynamoDB doesn't seem to short circuit the expression. I get this error regardless: ValidationException: The provided expression refers to an attribute that does not exist in the item.

params.ExpressionAttributeNames = {
    '#checkIns': 'checkIns'
};
params.ExpressionAttributeValues = {
  ':newCheckIn': [newDateString],
  ':justDatePart': justDatePart
};
params.UpdateExpression = 'SET #checkIns = list_append(:newCheckIn, #checkIns)';

// make sure task is not already checked in today
params.ConditionExpression =
  'attribute_not_exists(#checkIns) OR (NOT begins_with(#checkIns[0], :justDatePart))';

return Table.updateAsync({ID}, params); // using dynogels-promisified

I can't seem get it to short circuit by checking whether the attribute exists first. Also I tried to use if_not_exists() to replace checkIns[0] with a meaningless string, but I get this error:

ValidationException: Invalid ConditionExpression: The function is not allowed in a condition expression; function: if_not_exists

Anyone have any ideas?

Clarkie
  • 7,490
  • 9
  • 39
  • 53

1 Answers1

2

The problem was with the UpdateExpression and not the ConditionExpression.

The following update fixes the problem:

  params.UpdateExpression = 'SET #checkIns = list_append(:newCheckIn, if_not_exists(#checkIns, :empty_list))';
LuFFy
  • 8,799
  • 10
  • 41
  • 59