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

fix(lib-dynamodb): fix marshalling of list attributes in UpdateCommand #3719

Closed
wants to merge 1 commit into from

Conversation

brendanhonea
Copy link

Description

I recently found a bug in the @aws-sdk/lib-dynamodb package (document client) . The UpdateCommand was failing when providing a list attribute to AttributeUpdates. UpdateCommand allows you to supply native attribute values to update a dynamo record like so:

new UpdateCommand({
    TableName: "SomeTable",
    Key: {
      pk: "somePk",
      sk: "someSk",
    },
    AttributeUpdates: {
        stringAttr: { Action: "PUT", Value: "Some string value" },
        numberAttr: { Action: "PUT", Value: 12345 },
        listAttr: { Action: "PUT", Value: ["list item 1", "list item 2"] },
    },
    ReturnValues: "ALL_NEW",
})

The issue I was running in to was that list attributes were not being marshaled properly and causing a JSON parsing error downstream in the library. The marshaler would convert the above AttributeUpdates map into:

AttributeUpdates: {
        stringAttr: { Action: "PUT", Value: {S: "some string value"} },
        numberAttr: { Action: "PUT", Value: { N: "12345"} },
        listAttr: { Action: "PUT", Value: [ { S: "list item 1"} , { S: "list item 2" } ] }, // Here is the problem
    },

The dynamodb client expects lists to also be prefaced with an attribute type like so

AttributeUpdates: {
        stringAttr: { Action: "PUT", Value: {S: "some string value"} },
        numberAttr: { Action: "PUT", Value: { N: "12345"} },
        listAttr: { Action: "PUT", Value: { L: [ { S: "list item 1"} , { S: "list item 2" } ] } }, // This is what dynamodb needs to see
    },

This PR addresses the issue in the lib-dynamo marshaling code so that lists are passed properly to the dynamodb client. I added an optional parameter to the KeyNode type so that this only affects commands that need to process nodes in this fashion.

Testing

I wrote unit tests to ensure that the marshaling works properly and ran the entire test suite to test for breaking changes.

Additional Context

I could not regenerate clients due to Projection ec2.2016-11-15 failed: java.lang.OutOfMemoryError: Java heap space. I don't believe this was caused by my changes as I did not touch any EC2 code.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@brendanhonea brendanhonea requested a review from a team as a code owner June 20, 2022 23:29
@kuhe kuhe self-assigned this Jun 21, 2022
@kuhe kuhe added the pr/needs-review This PR needs a review from a Member. label Jun 21, 2022
@kuhe kuhe self-requested a review June 21, 2022 00:11
default:
return attributeValue;
}
return convertToAttr(data, options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed it with Brendan -- the main issue is that the interface of marshall, this function, should not be changed since I have seen that it is used independently.

The option could be implemented as a new marshallOptions entry and applied only to UpdateCommand.

@kuhe
Copy link
Contributor

kuhe commented Oct 5, 2023

superceded by #5306

@kuhe kuhe closed this Oct 5, 2023
@github-actions
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 Oct 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pr/needs-review This PR needs a review from a Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants