Skip to content
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

DocumentClient incorrectly marshalls binary data types when using convertClassInstanceToMap: true #5824

Closed
3 tasks done
dabrowne opened this issue Feb 26, 2024 · 4 comments
Closed
3 tasks done
Assignees
Labels
bug This issue is a bug. closed-for-staleness p2 This is a standard priority issue

Comments

@dabrowne
Copy link

dabrowne commented Feb 26, 2024

Checkboxes for prior research

Describe the bug

When writing data using DynamoDBDocumentClient with marshallOptions.convertClassInstanceToMap = true, binary data values are incorrectly written to Dynamo as the "M" (map) data type rather than the "B" (binary) data type.

SDK version number

@aws-sdk/lib-dynamodb@3.504.0

Which JavaScript Runtime is this issue in?

All

Details of the browser/Node.js/ReactNative version

All

Reproduction Steps

const client = DynamoDBDocumentClient.from(new DynamoDBClient(), {
  marshallOptions: {
    convertClassInstanceToMap: true,
  },
});

client.send(new PutCommand({
  TableName: "my-table",
  Item: {
    key: "my-key",
    data: Buffer.from("enchilada"),
  },
}));

Observed Behavior

The marshalled DynamoDB JSON that is written to the database for the data attribute contains a Map whose value is equivalent to the result of converting the Buffer to a plain object by iterating over its keys using Object.entries:

"data": {
  "M": {
   "0": {
    "N": "101"
   },
   "1": {
    "N": "110"
   },
   "2": {
    "N": "99"
   },
   "3": {
    "N": "104"
   },
   "4": {
    "N": "105"
   },
   "5": {
    "N": "108"
   },
   "6": {
    "N": "97"
   },
   "7": {
    "N": "100"
   },
   "8": {
    "N": "97"
   }
  }
}

Expected Behavior

The marshalled DynamoDB JSON that is written to the database should contain the data attribute as a binary value:

"data": {
  "B": "ZW5jaGlsYWRh"
}

Possible Solution

This bug was introduced with #5697 which blindly converts anything that has typeof of object into a plain JS object.

This fails to account for the fact that there are a large number of types that fit this signature but should be left intact, as is accounted for here and here.

I'd imagine this change has also broken marshalling for other data type such as Set.

Additional Information/Context

No response

@dabrowne dabrowne added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Feb 26, 2024
@kuhe kuhe self-assigned this Feb 26, 2024
@kuhe kuhe added p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Feb 26, 2024
@kuhe kuhe added the pending-release This issue will be fixed by an approved PR that hasn't been released yet. label Feb 26, 2024
@kuhe
Copy link
Contributor

kuhe commented Feb 27, 2024

Thanks for reporting this. A fix was released in https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.523.0.

https://www.npmjs.com/package/@aws-sdk/lib-dynamodb/v/3.523.0

@kuhe kuhe added closing-soon This issue will automatically close in 4 days unless further comments are made. and removed pending-release This issue will be fixed by an approved PR that hasn't been released yet. labels Feb 27, 2024
@dabrowne
Copy link
Author

Great turnaround. Thanks @kuhe!

@github-actions github-actions bot removed the closing-soon This issue will automatically close in 4 days unless further comments are made. label Feb 28, 2024
@kuhe kuhe added the closing-soon This issue will automatically close in 4 days unless further comments are made. label Feb 28, 2024
@github-actions github-actions bot added closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Mar 3, 2024
@github-actions github-actions bot closed this as completed Mar 3, 2024
@kuhe
Copy link
Contributor

kuhe commented Mar 8, 2024

Related report of the issue affecting AWS Lambda provided SDKs: #5868

Copy link

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 github-actions bot locked as resolved and limited conversation to collaborators Mar 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug. closed-for-staleness p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

2 participants