Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt attributes do not support $add in 0.8+ #588

Open
amccarthy1 opened this issue Sep 18, 2023 · 0 comments
Open

BigInt attributes do not support $add in 0.8+ #588

amccarthy1 opened this issue Sep 18, 2023 · 0 comments

Comments

@amccarthy1
Copy link
Contributor

I'm trying to upgrade from 0.7 to 0.8 (to eventually get to 1.0 when it's released) and I'm hitting some issues with bigints and addition. Specifically, the following type of query is very common in our codebase but seems to be unsupported:

  const TestEntity = new Entity({
    name: 'TestEntity',
    autoExecute: false,
    attributes: {
      // ...
      test_bigint: { type: 'bigint' },
      // ...
    }
  }

  it.only('succeeds setting a bigint field', async () => {
    await TestEntity.update({
      email: 'test-pk',
      sort: 'test-sk',
      test_bigint: { $add: BigInt(100) },
    }, { execute: true });
  })

Once you've setup a local dynamo, the above test case fails with:

  ● put › succeeds setting a bigint field

    ValidationException: Invalid UpdateExpression: Incorrect operand type for operator or function; operator: ADD, operand type: STRING, typeSet: ALLOWED_FOR_ADD_OPERAND

      759 |     }
      760 |
    > 761 |     const output = await this.DocumentClient.send( new UpdateCommand(updateParams))
          |                    ^
      762 |
      763 |     if (!shouldParse(options.parse, this.autoParse)) {
      764 |       return output as any

The DynamoDB update it's issuing looks like this:

{
  TableName: 'test-table',
  Key: { pk: 'test-pk', sk: 'test-sk' },
  UpdateExpression: 'SET #test_string = if_not_exists(#test_string,:test_string), #test_number_coerce = if_not_exists(#test_number_coerce,:test_number_coerce), #_ct = if_not_exists(#_ct,:_ct), #_md = :_md, #_et = if_not_exists(#_et,:_et) ADD #test_bigint :test_bigint',
  ExpressionAttributeNames: {
    '#test_string': 'test_string',
    '#test_number_coerce': 'test_number_coerce',
    '#_ct': '_ct',
    '#_md': '_md',
    '#_et': '_et',
    '#test_bigint': 'test_bigint'
  },
  ExpressionAttributeValues: {
    ':test_string': 'test string',
    ':test_number_coerce': 0,
    ':_ct': '2023-09-18T17:25:28.910Z',
    ':_md': '2023-09-18T17:25:28.910Z',
    ':_et': 'TestEntity',
    ':test_bigint': '100'
  }
}

(note that you need to configure the DynamoDBDocumentClient with wrapNumbers: true to get bigint support)

Notably, the test does pass if you pass test_bigint: BigInt(100), but the constructed query seems to be storing the value as a string, whereas under 0.7 it is stored as a Number type.

I'd be interested to help out with fixing this, but I'm not really sure where to start, since it seems like some things have changed with these internals since BigInt support was first added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant