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

DynamoDBDocument can't unmarshall null

Open vbanderov opened this issue 3 years ago • 0 comments

Checkboxes for prior research

Describe the bug

When trying to query for a record containing null value through DynamoDBDocument an error is thrown:

TypeError: Cannot read properties of null (reading 'S')

SDK version number

@aws-sdk/[email protected]

Which JavaScript Runtime is this issue in?

Node.js

Details of the browser/Node.js/ReactNative version

v16.16.0

Reproduction Steps

import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { DynamoDBDocument } from '@aws-sdk/lib-dynamodb';

const client = new DynamoDBClient({
  // ...
});

const document = DynamoDBDocument.from(client);

await document.put({
  TableName: 'table',
  Item: { 
    HashKey: 'hashkey',
    foo: null
   }
});

await document.query({
  TableName: 'table',
  ExpressionAttributeValues: { ':hk': 'hashkey' },
  KeyConditionExpression: `HashKey = :hk`,
});

Observed Behavior

An uncaught error is thrown:

error: TypeError: Cannot read properties of null (reading 'S')

Expected Behavior

The item is successfully returned by the query command.

Possible Solution

Probably need to check if value is null before trying to read property 'S' on it. Not sure where that happens though.

Additional Information/Context

No response

vbanderov avatar Aug 05 '22 23:08 vbanderov