-
Notifications
You must be signed in to change notification settings - Fork 592
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
DynamoDB Marshaller does not handle undefined property values #1816
Comments
@carlnordenfelt When a value undefined in a JS Object, we explicitly want to call it that value is undefined instead of removing it. Should marshaller remove keys for |
Hi, I guess it depends. Throwing an error seems a bit harsh. Keeping the value as In a way this realtes to the ES6 issue #1535. We sue ES6 classes and we convert these to Dynamo items using the V2 marshaller. What we don't do is check every property of the class for undefined but optimistically push them through the marshaller which gives us a valid DDB Item without the undefined values. Perhaps, if it is a concern, it could be a config option next to |
The DynamoDB AttributeValue doesn't have an undefined value. The closest attribute is of type
This should be considered as a bug, as the key is already declared but not defined and shouldn't be removed by marshaller. As per MDN:
WDYT? |
It should probably not be converted to NULL, I agree with that. I've played around with the v2 sdk to see how the behaviour differs, for good and bad, and the following works, the const aws = require('aws-sdk');
const dynamo = new aws.DynamoDB.DocumentClient();
(async () => {
const v2Item = {
'hashKey': 'example',
bar: undefined,
};
await dynamo.put({ TableName: 'tableName', Item: v2Item }).promise();
})(); I tried an equivalent request with V3 PutItemCommand and it throws an error early on before sending the request. /.../ddb-marshall/node_modules/@aws-sdk/client-dynamodb/dist/cjs/models/models_0.js:1081
if (value.S !== undefined)
^
TypeError: Cannot read property 'S' of undefined To be honest, I am not sure what to think. |
This is also a problem with the types as seen in #1647. I'm adding this here because this is specific to the interface Test {
expireAt?: string;
actual: string;
} DynamoDB allows for optional properties, such as TTL properties, but const: Test = {
expireAt: undefined,
actual: "string"
} may be invalid an object like: const: Test = {
actual: "string"
} is expected and should be valid. I'm not sure how to handle this, but I've already had to struggle with this because our data model allows for optional properties on some objects. |
Update: We'll prioritize fixing this with |
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. |
Describe the bug
The
@aws-sdk/util-dynamodb
marshaller throws an error if provided an undefined property value.Version 2 of the equivalent marshaller handled undefined properties gracefully.
It may not necessarily be considered a bug but it is a breaking change that has a rather big impact on existing code relying on marshalling arbitrary objects without first checking for undefined properties.
SDK version number
@aws-sdk/util-dynamodb 3.0.0
Is the issue in the browser/Node.js/ReactNative?
Node.js
Details of the browser/Node.js/ReactNative version
v15.2.1
To Reproduce (observed behavior)
The following code example will throw an error when marshalling with the v3 marshaller.
The v2 marshalling is included to highlight the difference between v2/v3.
There is a fairly easy to use work-around but it can have some unforeseen consequences:
Expected behavior
As per the v2 marshaller, undefined key/values should be ignored.
Somewhat related issue: #1647
The text was updated successfully, but these errors were encountered: