Skip to content

Commit 371f05c

Browse files
authored
fix(lib-dynamodb): read input from middleware instead of command (#6984)
1 parent f46323d commit 371f05c

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

lib/lib-dynamodb/src/baseCommand/DynamoDBDocumentClientCommand.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export abstract class DynamoDBDocumentClientCommand<
5353
args: InitializeHandlerArguments<Input | BaseInput>
5454
): Promise<InitializeHandlerOutput<Output | BaseOutput>> => {
5555
setFeature(context, "DDB_MAPPER", "d");
56-
args.input = marshallInput(this.input, this.inputKeyNodes, marshallOptions);
56+
args.input = marshallInput(args.input, this.inputKeyNodes, marshallOptions);
5757
context.dynamoDbDocumentClientOptions =
5858
context.dynamoDbDocumentClientOptions || DynamoDBDocumentClientCommand.defaultLogFilterOverrides;
5959

lib/lib-dynamodb/src/test/lib-dynamodb.e2e.spec.ts

+41-8
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,19 @@ import {
1414
DynamoDBDocument,
1515
ExecuteStatementCommandOutput,
1616
ExecuteTransactionCommandOutput,
17+
GetCommandInput,
1718
GetCommandOutput,
1819
NumberValue,
1920
PutCommandOutput,
21+
QueryCommandInput,
2022
QueryCommandOutput,
23+
ScanCommandInput,
2124
ScanCommandOutput,
2225
TransactGetCommandOutput,
2326
TransactWriteCommandOutput,
2427
UpdateCommandOutput,
2528
} from "@aws-sdk/lib-dynamodb";
29+
import { HttpRequest } from "@smithy/protocol-http";
2630
import { afterAll, beforeAll, describe, expect, test as it, vi } from "vitest";
2731

2832
// expected running time: table creation (~20s) + operations 10s
@@ -81,6 +85,43 @@ describe(
8185
},
8286
});
8387

88+
doc.middlewareStack.add(
89+
(next, context) => async (args) => {
90+
if (context.commandName === "GetCommand" || context.commandName === "GetItemCommand") {
91+
(args.input as GetCommandInput).ConsistentRead = true;
92+
}
93+
if (context.commandName === "QueryCommand") {
94+
(args.input as QueryCommandInput).ConsistentRead = true;
95+
}
96+
if (context.commandName === "ScanCommand") {
97+
(args.input as ScanCommandInput).ConsistentRead = true;
98+
}
99+
return next(args);
100+
},
101+
{
102+
step: "initialize",
103+
name: "SetConsistentReadMiddleware",
104+
override: true,
105+
}
106+
);
107+
108+
doc.middlewareStack.add(
109+
(next, context) => async (args) => {
110+
const { request } = args;
111+
if (HttpRequest.isInstance(request)) {
112+
if (["GetCommand", "GetItemCommand", "QueryCommand", "ScanCommand"].includes(context.commandName ?? "")) {
113+
expect(request.body).toContain(`"ConsistentRead":true`);
114+
}
115+
}
116+
return next(args);
117+
},
118+
{
119+
step: "finalizeRequest",
120+
name: "VerifyConsistentReadMiddleware",
121+
override: true,
122+
}
123+
);
124+
84125
function throwIfError(e: unknown) {
85126
if (e instanceof Error) {
86127
throw e;
@@ -243,7 +284,6 @@ describe(
243284

244285
log.read[id] = await doc
245286
.get({
246-
ConsistentRead: true,
247287
TableName,
248288
Key: {
249289
id,
@@ -338,7 +378,6 @@ describe(
338378
for (const [k] of Object.entries(data)) {
339379
log.executeTransactionReadBack[k] = await doc
340380
.get({
341-
ConsistentRead: true,
342381
TableName,
343382
Key: {
344383
id: k + "-exec-transact",
@@ -358,7 +397,6 @@ describe(
358397
for (const [k] of Object.entries(data)) {
359398
log.executeStatementReadBack[k] = await doc
360399
.get({
361-
ConsistentRead: true,
362400
TableName,
363401
Key: {
364402
id: k + "-statement",
@@ -400,7 +438,6 @@ describe(
400438
ExpressionAttributeValues: {
401439
":id": "map",
402440
},
403-
ConsistentRead: true,
404441
})
405442
.catch(passError);
406443

@@ -415,7 +452,6 @@ describe(
415452
":data1": data.list,
416453
":data2": data.map,
417454
},
418-
ConsistentRead: true,
419455
})
420456
.catch(passError);
421457

@@ -439,7 +475,6 @@ describe(
439475
Key: {
440476
id: "undefinedColumns",
441477
},
442-
ConsistentRead: true,
443478
})
444479
.catch(passError);
445480

@@ -461,7 +496,6 @@ describe(
461496

462497
log.updateReadBack[id] = await doc
463498
.get({
464-
ConsistentRead: true,
465499
TableName,
466500
Key: {
467501
id,
@@ -530,7 +564,6 @@ describe(
530564

531565
log.classInstanceConversion.read = await doc
532566
.get({
533-
ConsistentRead: true,
534567
TableName,
535568
Key: {
536569
id: "classInstance",

0 commit comments

Comments
 (0)