aws-sdk-js-v3
aws-sdk-js-v3 copied to clipboard
[dynamodb] Query input parameter validation error with paginator
Describe the bug
The query input is working when using just the client but failing for paginator.
TypeError: Cannot read property '0' of undefined
at Object.AttributeValue.visit (./node_modules/@aws-sdk/client-dynamodb/models/models_0.ts:6296:36)
at serializeAws_json1_0AttributeValue (./node_modules/@aws-sdk/client-dynamodb/protocols/Aws_json1_0.ts:5566:25)
at ./node_modules/@aws-sdk/client-dynamodb/protocols/Aws_json1_0.ts:6161:14
at Array.reduce (<anonymous>)
at serializeAws_json1_0ExpressionAttributeValueMap (./node_modules/@aws-sdk/client-dynamodb/protocols/Aws_json1_0.ts:6155:32)
at serializeAws_json1_0QueryInput (./node_modules/@aws-sdk/client-dynamodb/protocols/Aws_json1_0.ts:6740:36)
at Object.serializeAws_json1_0QueryCommand (./node_modules/@aws-sdk/client-dynamodb/protocols/Aws_json1_0.ts:786:25)
at serialize (./node_modules/@aws-sdk/client-dynamodb/commands/QueryCommand.ts:133:12)
at ./node_modules/@aws-sdk/middleware-serde/src/serializerMiddleware.ts:18:27
at ./node_modules/@aws-sdk/middleware-logger/src/loggerMiddleware.ts:22:28
Your environment
MacOS
SDK version number
"@aws-sdk/client-dynamodb": "3.19.0",
"@aws-sdk/lib-dynamodb": "3.19.0",
"@aws-sdk/util-dynamodb": "3.19.0",
Is the issue in the browser/Node.js/ReactNative?
Node.js
Details of the browser/Node.js/ReactNative version
v14.16.1
Steps to reproduce
const client = new DynamoDBClient({ region: "us-east-1" });
let queryCommandInput: QueryCommandInput = {
TableName: "DBIRTH",
ExpressionAttributeValues: {":PK": "something" },
KeyConditionExpression: "PK = :PK",
};
// succeeds
const response = await client.send(new QueryCommand(queryCommandInput));
// fails
const paginator = paginateQuery(
{
client,
pageSize,
startingToken: lastEvaluatedKey,
},
queryCommandInput
);
try {
const page = await paginator.next();
console.log(page.value.Items);
} catch (err) {
console.error(err);
}
Observed behavior
The query input is working when using just the client but failing for paginator.
Expected behavior
The query input should work the same for client and paginator.
Additional context
I believe this is related to a similar problem in boto/boto3#2300. The issue is not fixed but shows a workaround. Please share if there's a similar work around applicable here.
Hi @twitu. I've encountered the same problem and found out that using the marshall
function on ExpressionAttributeValues
helps to workaround this issue.
// marshall ExpressionAttributeValues
let queryCommandInput: QueryCommandInput = {
TableName: "DBIRTH",
ExpressionAttributeValues: marshall({ ":PK": "something" }),
KeyConditionExpression: "PK = :PK",
};
// works
const paginator = paginateQuery(
{
client,
pageSize,
startingToken: lastEvaluatedKey,
},
queryCommandInput
);
try {
const page = await paginator.next();
console.log(page.value.Items);
} catch (err) {
console.error(err);
}
Hi @twitu. Obviously this example from aws is wrong: https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.04.html
I just had this issue and fixed with this, change your input to:
let queryCommandInput: QueryCommandInput = {
TableName: "DBIRTH",
// The S is the data type of the value, S means string
ExpressionAttributeValues: {":PK": { S: "something" } },
KeyConditionExpression: "PK = :PK",
};
Hey everyone. Apologies the issue fell out of queue. Using something like mentioned in @Wyfy0107 should resolve the issue.
https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html mentions "You would first need to specify ExpressionAttributeValues as follows:
{ ":avail":{"S":"Available"}, ":back":{"S":"Backordered"}, ":disc":{"S":"Discontinued"} "}
Im not sure what example was followed but looking at the boto issue too this can be mentioned with examples too. https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GettingStarted.NodeJs.04.html doesnt seem to redirect correctly, can anyone share the example from doc link?
Greetings! We’re closing this issue because it has been open a long time and hasn’t been updated in a while and may not be getting the attention it deserves. We encourage you to check if this is still an issue in the latest release and if you find that this is still a problem, please feel free to comment or open a new issue.
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.