aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
DynamoDBDocument can't unmarshall null
Checkboxes for prior research
- [X] I've gone through Developer Guide and API reference
- [X] I've checked AWS Forums and StackOverflow.
- [X] I've searched for previous similar issues and didn't find any solution.
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