aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
marshallInput fails to marshall AttributeUpdates for map attributes
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
marshallInput({ AttributeUpdates: { customer: { Action: "PUT", Value: { first_name: 'Andrea', last_name: 'Gariboldi' } } } }, [{"key":"AttributeUpdates","children":{"children":[{"key":"Value"}]}}]))
returns
{"AttributeUpdates":{"customer":{"Action":"PUT","Value":{"first_name":{"S":"Andrea"},"last_name":{"S":"Gariboldi"}}}}}
But it should return
{"AttributeUpdates":{"customer":{"Action":"PUT","Value":{ "M": {"first_name":{"S":"Andrea"},"last_name":{"S":"Gariboldi"}}}}}}
Then it fails shortly after due to the fact that Value has an unknown type
TypeError: Cannot read property '0' of undefined
at Object.AttributeValue.visit (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/models/models_0.js:457:40)
at serializeAws_json1_0AttributeValue (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3025:38)
at serializeAws_json1_0AttributeValueUpdate (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3049:45)
at /code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3020:20
at Array.reduce (<anonymous>)
at serializeAws_json1_0AttributeUpdates (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3014:34)
at serializeAws_json1_0UpdateItemInput (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:4216:31)
at serializeAws_json1_0UpdateItemCommand (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:476:27)
at serialize (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/commands/UpdateItemCommand.js:30:72)
at /code/api/node_modules/@aws-sdk/middleware-serde/dist-cjs/serializerMiddleware.js:5:27
at /code/api/node_modules/@aws-sdk/lib-dynamodb/dist-cjs/baseCommand/DynamoDBDocumentClientCommand.js:11:20
SDK version number
@aws-sdk/[email protected]
Which JavaScript Runtime is this issue in?
Node.js
Details of the browser/Node.js/ReactNative version
v14.18.1
Reproduction Steps
JSON.stringify(require('./node_modules/@aws-sdk/lib-dynamodb/dist-cjs/commands/utils.js').marshallInput({ AttributeUpdates: { customer: { Action: "PUT", Value: { first_name: 'Andrea', last_name: 'Gariboldi' } } } }, [{"key":"AttributeUpdates","children":{"children":[{"key":"Value"}]}}]))
Observed Behavior
I got his error while trying to update an object with the document client
TypeError: Cannot read property '0' of undefined
at Object.AttributeValue.visit (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/models/models_0.js:457:40)
at serializeAws_json1_0AttributeValue (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3025:38)
at serializeAws_json1_0AttributeValueUpdate (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3049:45)
at /code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3020:20
at Array.reduce (<anonymous>)
at serializeAws_json1_0AttributeUpdates (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3014:34)
at serializeAws_json1_0UpdateItemInput (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:4216:31)
at serializeAws_json1_0UpdateItemCommand (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:476:27)
at serialize (/code/api/node_modules/@aws-sdk/client-dynamodb/dist-cjs/commands/UpdateItemCommand.js:30:72)
at /code/api/node_modules/@aws-sdk/middleware-serde/dist-cjs/serializerMiddleware.js:5:27
at /code/api/node_modules/@aws-sdk/lib-dynamodb/dist-cjs/baseCommand/DynamoDBDocumentClientCommand.js:11:20
Expected Behavior
It is possible to set map attributes using the document client on a dynamodb item
Possible Solution
No response
Additional Information/Context
No response
Hi @aaaristo, thanks for opening this issue. I tried to reproduce the reported behavior but in my tests I got successfully results. Please see below:
const {marshallInput} = require('../node_modules/@aws-sdk/lib-dynamodb/dist-cjs/commands/utils.js');
const response = marshallInput({ AttributeUpdates: { customer: { Action: "PUT", Value: { first_name: 'Andrea', last_name: 'Gariboldi' } } } }, [{"key":"AttributeUpdates","children":{"children":[{"key":"Value"}]}}]);
console.log('Response: ', JSON.stringify(response));
Output:
Response: {"AttributeUpdates":{"customer":{"Action":"PUT","Value":{"first_name":{"S":"Andrea"},"last_name":{"S":"Gariboldi"}}}}}
The versions I tested with are:
- @aws-sdk/[email protected]
- @aws-sdk/[email protected]
So, could you please try updating to the latest version?
Thanks!
@yenfryherrerafeliz The output above is not correct, you are trying to set a map attribute. And it will fail if you try to send an actual UpdateItem command.
It should be
{"AttributeUpdates":{"customer":{"Action":"PUT","Value":{ "M": {"first_name":{"S":"Andrea"},"last_name":{"S":"Gariboldi"}}}}}}
See https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_UpdateItem.html for reference.
@yenfryherrerafeliz The output above is not correct, you are trying to set a map attribute. And it will fail if you try to send an actual UpdateItem command.
Hi @aaaristo, I can confirm this is an issue. Unfortunately the marshallInput function does not handle map attributes yet, nonetheless I will mark this issue to be reviewed, so we can further address this.
Thanks!
given that aws-sdk v3 is the new default, I would assume that it is stable and feature complete (general availability 2 years as of today). This seems to be a pretty big issue for anyone using DynamoDB and is a blocker for switching to v3. Can we expect a fix soon? If not, I think this should be added to the Known Issues
@ajredniwja you have an example fix here, I'm not familiar with the build system but if you can point me to some doc maybe I can make a test for it
https://github.com/aws/aws-sdk-js-v3/pull/3850
While migrating my code to use v3, I also experienced the issue with both Map attributes and Array Attributes..... It is a blocker for me too. I will appreciate if the issue could be fixed
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.