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

Normalise Scan response shape when using "RawAWSFilter" #320

Merged
merged 2 commits into from
Mar 22, 2018

Conversation

DanielBoa
Copy link
Contributor

Problem

When using a raw AWS filter to Scan the returned Item shape is not consistent with a regular Scan.

Instead of:

NewModel {
    name: 'Snoopy',
    details: { timeWakeUp: '8am', timeSleep: '8pm' },
    ownerId: 19,
    color:  ['black', 'white'],
    cartoon: 'true',
    breed: 'Beagle'
}

We get:

NewModel {
    name: 'Snoopy',
    details: { timeWakeUp: '8am', timeSleep: '8pm' },
    ownerId: 19,
    color: Set { values: ['black', 'white'], type: 'String' },
    cartoon: 'true',
    breed: 'Beagle'
}

This is happening because AWS.DynamoDB.DocumentClient creates Set instances for attributes of type StringSet etc. These aren't native instances of Set but rather a custom AWS Class which isn't exposed.

Solution

When mapping over the returned objects within Scan.js I iterate over each items properties and check for such instances to convert them to regular array instances.

…items nows have any values of type DynamoDBSet unpacked to normal Array's to keep consistency with default scan behaviour.
@coveralls
Copy link

coveralls commented Mar 20, 2018

Coverage Status

Coverage increased (+0.2%) to 82.46% when pulling 9d96d44 on DanielBoa:master into 8f5c192 on automategreen:master.

@fishcharlie fishcharlie added this to the v0.8.7 milestone Mar 20, 2018
Copy link
Contributor

@brandongoode brandongoode left a comment

Choose a reason for hiding this comment

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

I would like to have seen a test case added, but the changes are minimal.

Very clever getting the constructor to check the type.

@fishcharlie
Copy link
Member

@brandongoode I created an issue #322, to track maybe adding tests for this PR in the future. For now we can approve it and add them later on.

@fishcharlie fishcharlie merged commit da43df3 into dynamoose:master Mar 22, 2018
@fishcharlie
Copy link
Member

Thanks for this @DanielBoa!!

@fishcharlie fishcharlie mentioned this pull request Mar 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants