dynamodb-toolbox icon indicating copy to clipboard operation
dynamodb-toolbox copied to clipboard

Update using dashes

Open ThomasAribart opened this issue 5 years ago • 4 comments

FooEntity.update({
  dictionary: {
    $set: {
      'field-with-dash': 'bar',
    },
  },
})

This update will fail as the update method will generate an ExpressionAttributeName containing { '#field-with-dash': 'field-with-dash' } and the dynamoDb client will throw an error Invalid ExpressionAttributeName key as it doesn't handle the #field-with-dash key... 😞

ThomasAribart avatar Nov 23 '20 10:11 ThomasAribart

Good catch. Looks like I'm just taking the attribute name and prefixing it with a #, but clearly that will cause issues. I should be able to switch it to an incrementing numerical index approach like I used for the projectionBuilder.

jeremydaly avatar Nov 23 '20 14:11 jeremydaly

I'm also hitting the same issue, but due to using spaces not dashes. For example, when running this:

FooEntity.update({
  dictionary: {
    $set: {
      'Hello World': 'bar',
    },
  },
})

...you get the error:

ValidationException: ExpressionAttributeNames contains invalid key: Syntax error; key: "#dictionary_Hello World"

PR #96 looks like a good option, but it requires extra logic and I sorta feel like this use-case should work out of the box.

@jeremydaly Did you have an implementation in mind for this, or were you intending to merge #96? I'm happy to assist, either creating an alternative PR or updating the existing one?

Brilliant library BTW! Really enjoying using it.

thekiwi avatar Jan 11 '21 21:01 thekiwi

I'm also facing the same issue when using uuid in set keys:

FooEntity.update({
  dictionary: {
    $set: {
      'b2333002-55be-47b8-8fbb-2e1ed19a5ab3': 'bar',
    },
  },
})

Wingjam avatar Sep 02 '21 20:09 Wingjam

I'm also facing the same issue. Any update on this ??

ankitaabad avatar May 07 '22 00:05 ankitaabad