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

A null ExclusiveStartKey produces promise rejection when sending QueryCommand or ScanCommand #3568

Closed
korostelevm opened this issue Apr 26, 2022 · 4 comments
Assignees
Labels
bug This issue is a bug.

Comments

@korostelevm
Copy link

korostelevm commented Apr 26, 2022

Describe the bug

When sending a query or scan command with a null value for ExclusiveStartKey, the sdk fails with an unhandled promise rejection. Null values were supported before and are often used in pagination code.

If this change was intended, it should produce a ValidationError with an appropriate message.

Your environment

SDK version number

@aws-sdk/client-dynamodb@3.77
@aws-sdk/lib-dynamodb@3.77

Is the issue in the browser/Node.js/ReactNative?

Node.js

Details of the browser/Node.js/ReactNative version

v14.17.0

Steps to reproduce

This code fails with 3.77 but works in 3.53


const { DynamoDBDocumentClient, QueryCommand , ScanCommand} = require("@aws-sdk/lib-dynamodb")
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb")
const REGION = process.env.AWS_REGION || 'us-east-2'
const ddbClient = new DynamoDBClient({ region: REGION });
const docClient = DynamoDBDocumentClient.from(ddbClient);

let params = {
    TableName: 'table',
    ExclusiveStartKey: null
  };
let res = await docClient.send(new ScanCommand(params))
console.log(res)


Observed behavior

A clear and concise description of what happens.

Resulting error

}
(node:69395) UnhandledPromiseRejectionWarning: TypeError: Cannot read property '0' of undefined
    at Object.AttributeValue.visit (/Users/mike/Dropbox/codes/db-sdk/node_modules/@aws-sdk/client-dynamodb/dist-cjs/models/models_0.js:1319:40)
    at serializeAws_json1_0AttributeValue (/Users/mike/Dropbox/codes/db-sdk/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3134:38)
    at /Users/mike/Dropbox/codes/db-sdk/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3746:20
    at Array.reduce (<anonymous>)
    at serializeAws_json1_0Key (/Users/mike/Dropbox/codes/db-sdk/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:3740:34)
    at serializeAws_json1_0QueryInput (/Users/mike/Dropbox/codes/db-sdk/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:4069:32)
    at serializeAws_json1_0QueryCommand (/Users/mike/Dropbox/codes/db-sdk/node_modules/@aws-sdk/client-dynamodb/dist-cjs/protocols/Aws_json1_0.js:356:27)
    at serialize (/Users/mike/Dropbox/codes/db-sdk/node_modules/@aws-sdk/client-dynamodb/dist-cjs/commands/QueryCommand.js:30:67)
    at /Users/mike/Dropbox/codes/db-sdk/node_modules/@aws-sdk/middleware-serde/dist-cjs/serializerMiddleware.js:5:27
    at /Users/mike/Dropbox/codes/db-sdk/node_modules/@aws-sdk/middleware-logger/dist-cjs/loggerMiddleware.js:6:28

Expected behavior

A clear and concise description of what you were expecting to happen.
Expected it to behave as if ExclusiveStartKey was not provided and scan/query forward at the index start

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context

Add any other context about the problem here.

@korostelevm korostelevm added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Apr 26, 2022
@korostelevm
Copy link
Author

korostelevm commented Apr 26, 2022

Looks like this is the change that introduced the issue

In #3539 @kuhe @trivikr

@kuhe kuhe self-assigned this Apr 26, 2022
@kuhe kuhe removed the needs-triage This issue or PR still needs to be triaged. label Apr 26, 2022
@kuhe
Copy link
Contributor

kuhe commented Apr 26, 2022

Hi @korostelevm, I'm sorry that this change was breaking for your application.

The change made in #3539 fixes and allows non-map values, and indeed falsy values, to be converted correctly in @aws-sdk/lib-dynamodb, where previously they were unintentionally ignored.

Please leave the key out of your request object when not providing a compatible value. As a second option, use a value of undefined instead of null.

We don't currently plan to add validation, because there is usually no client side runtime type validation. If you use TypeScript with strict null checks, that will block null from being allowed in this case.

@korostelevm
Copy link
Author

Thanks for taking a look, faced the original issue in the past as well. Having to choose between workarounds, I think I'll take this one 😂

@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 May 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants