aws-sdk-js-v3 icon indicating copy to clipboard operation
aws-sdk-js-v3 copied to clipboard

MIGRATION ISSUE: Undocumented change in the behaviour of DynamoDB marshalling

Open andrejleitner opened this issue 1 year ago • 2 comments

Pre-Migration Checklist

Which JavaScript Runtime is this issue in?

Node.js (includes AWS Lambda)

AWS Lambda Usage

  • [X] Yes, my application is running on AWS Lambda.
  • [X] No, my application is not running on AWS Lambda.

Describe the Migration Issue

It appears that version 2 automatically omitted undefined values. To restore this "feature" in version 3, the removeUndefinedValues option must be set. I did not find this mentioned in the migration guide or notes.

Code Comparison

import { DynamoDB } from 'aws-sdk';
import { marshall } from '@aws-sdk/util-dynamodb';

const sample = {
    foo: 'test',
    bar: undefined,
};
console.log('sample', sample);

const marshalledV2 = DynamoDB.Converter.marshall(sample);
console.log('marshalledV2', marshalledV2);

const marshalledV3 = marshall(sample, { removeUndefinedValues:true });
console.log('marshalledV3', marshalledV3);

Observed Differences/Errors

  • removeUndefinedValues option not set:
❯ pnpm ts-node asd.ts
sample { foo: 'test', bar: undefined }
marshalledV2 { foo: { S: 'test' } }
~/.../@aws-sdk/util-dynamodb/dist-cjs/index.js:99
  throw new Error(`Pass options.removeUndefinedValues=true to remove undefined values from map/array/set.`);
...
  • removeUndefinedValues set to true:
❯ pnpm ts-node asd.ts
sample { foo: 'test', bar: undefined }
marshalledV2 { foo: { S: 'test' } }
marshalledV3 { foo: { S: 'test' } }

Additional Context

https://github.com/aws/aws-sdk-js-v3/issues/1816 https://github.com/aws/aws-sdk-js-v3/pull/1840

andrejleitner avatar Jan 24 '24 16:01 andrejleitner

Hi @andrejleitner ,

Thanks for bringing this up. We will add it to the migration guide.

All the best, Ran~

RanVaknin avatar Jan 25 '24 02:01 RanVaknin

So here is the solution: https://github.com/aws/aws-sdk-js-v3/blob/main/UPGRADING.md#undefined-values-in-when-marshalling

u11d-michal-miler avatar May 18 '24 08:05 u11d-michal-miler

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

github-actions[bot] avatar Jul 27 '24 00:07 github-actions[bot]