fix(dynamodb): reject ConsistentRead on GSI Scan (#2931)

Query already rejected ConsistentRead=true on a global secondary index,
but Scan silently performed the read. AWS returns ValidationException
'Consistent reads are not supported on global secondary indexes' for
both operations.

Extract the check into rejectConsistentReadOnGsi and apply it to both
handlers; strongly consistent reads on tables and LSIs stay legal.

Reproduced with paritysuite/dynamodb-conformance
(tests/tier3/error-messages/indexReads.test.ts): the Scan case failed
against 2.0.1 and passes with this change; the in-repo
DynamoDbAccessPathIntegrationTest gains a wire-level Scan case plus an
LSI-acceptance guard, and the Java SDK compat twin covers both ops.

Signed-off-by: Kévin Dehoux <dehoux.kevin@gmail.com>
This commit is contained in:
Kévin Dehoux authored and GitHub committed 2026-09-02 10:59:33 -04:00
1 parent fad54f3c7a
commit 6dec21479b
3 files changed
+38 -10

No files matched your search

@@ -193,6 +193,10 @@ class DynamoDbAccessPathValidationTest {
.keyConditionExpression("#status = :status")
.expressionAttributeNames(Map.of("#status", "status"))
.expressionAttributeValues(Map.of(":status", value("open")))));
assertValidationException(() -> ddb.scan(request -> request
.tableName(TABLE)
.indexName("status-index")
.consistentRead(true)));
}
@Test
@@ -870,16 +870,7 @@ public class DynamoDbJsonHandler {
keyConditionExpr, filterExpr, queryFilter, exprAttrNames, exprAttrValues);
DynamoDbAccessPathValidator.validateSelection(queryTable, queryAccessPath, select,
projectionExpression, attributesToGet, exprAttrNames);
// ConsistentRead on GSI check
boolean consistentRead = request.path("ConsistentRead").asBoolean(false);
if (consistentRead && indexName != null) {
if (queryTable.findGsi(indexName).isPresent()) {
throw new AwsException("ValidationException",
"Consistent reads are not supported on global secondary indexes", 400);
}
}
rejectConsistentReadOnGsi(request, queryAccessPath);
// Validate EAN/EAV usage when using expression format
if (keyConditionExpr != null) {
// Check undefined #tokens in FilterExpression
@@ -946,6 +937,13 @@ public class DynamoDbJsonHandler {
return Response.ok(response).build();
}
private static void rejectConsistentReadOnGsi(JsonNode request, DynamoDbAccessPath accessPath) {
if (request.path("ConsistentRead").asBoolean(false) && accessPath.isGlobalSecondaryIndex()) {
throw new AwsException("ValidationException",
"Consistent reads are not supported on global secondary indexes", 400);
}
}
private Response handleScan(JsonNode request, String region) {
String tableName = request.path("TableName").asText();
String filterExpr = request.has("FilterExpression")
@@ -1017,6 +1015,7 @@ public class DynamoDbJsonHandler {
DynamoDbAccessPath scanAccessPath = DynamoDbAccessPath.resolve(scanTable, indexNameScan);
DynamoDbAccessPathValidator.validateSelection(scanTable, scanAccessPath, select,
projectionExpressionScan, attributesToGetScan, exprAttrNames);
rejectConsistentReadOnGsi(request, scanAccessPath);
if (exclusiveStartKey != null) {
validateExclusiveStartKey(exclusiveStartKey, scanTable, scanAccessPath, true);
@@ -286,6 +286,31 @@ class DynamoDbAccessPathIntegrationTest {
.body("message", equalTo("Consistent reads are not supported on global secondary indexes"));
}
@Test
@Order(10)
void scanGsiRejectsConsistentReads() {
request("DynamoDB_20120810.Scan", """
{
"TableName":"%s",
"IndexName":"status-index",
"ConsistentRead":true
}
""".formatted(TABLE))
.statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("Consistent reads are not supported on global secondary indexes"));
// Consistent reads stay legal on a local secondary index.
request("DynamoDB_20120810.Scan", """
{
"TableName":"%s",
"IndexName":"alternate-index",
"ConsistentRead":true
}
""".formatted(TABLE))
.statusCode(200);
}
@Test
@Order(9)
void queryAndScanRejectWrongExclusiveStartKeyTypes() {