fix(dynamodb): match AWS for unprojected GSI attributes in Query, Scan and PartiQL (#5911)

* fix(dynamodb): use the AWS wording for unprojected GSI attributes in Query and Scan

* refactor(dynamodb): share the unprojected GSI attribute error with PartiQL

* fix(dynamodb): check PartiQL GSI columns after the WHERE clause

AWS reports a key type mismatch, overlapping ranges, too many reads and an
unprojected filter attribute before an unprojected column. It also lists
each column root once.

* fix(dynamodb): keep rejecting a projection path that starts with a list index
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-10-18 00:55:47 -04:00
1 parent b55014ddef
commit 61102a7c4e
7 files changed
+111 -36

No files matched your search

@@ -223,17 +223,34 @@ class DynamoDbAccessPathIntegrationTest {
""".formatted(TABLE);
request("DynamoDB_20120810.Query", query)
.statusCode(400)
.body("__type", equalTo("ValidationException"));
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("One or more parameter values were invalid: "
+ "Global secondary index status-index does not project [details]"));
request("DynamoDB_20120810.Scan", """
{
"TableName":"%s",
"IndexName":"status-index",
"ProjectionExpression":"details"
"ProjectionExpression":"zeta.a, details, zeta.b"
}
""".formatted(TABLE))
.statusCode(400)
.body("__type", equalTo("ValidationException"));
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("One or more parameter values were invalid: "
+ "Global secondary index status-index does not project [zeta, details]"));
request("DynamoDB_20120810.Scan", """
{
"TableName":"%s",
"IndexName":"status-index",
"Select":"ALL_ATTRIBUTES"
}
""".formatted(TABLE))
.statusCode(400)
.body("__type", equalTo("ValidationException"))
.body("message", equalTo("One or more parameter values were invalid: "
+ "Select type ALL_ATTRIBUTES is not supported for global secondary index status-index "
+ "because its projection type is not ALL"));
}
@Test
@@ -336,13 +336,29 @@ class DynamoDbAccessPathValidatorTest {
table, gsiPath, "SPECIFIC_ATTRIBUTES", "zeta, details",
null, null));
assertEquals("One or more parameter values were invalid: Global secondary index "
+ "status-index does not project details, zeta", projectionError.getMessage());
assertThrows(AwsException.class, () -> DynamoDbAccessPathValidator.validateGsiProjection(
table, gsiPath, "ALL_ATTRIBUTES", null, null, null));
+ "status-index does not project [zeta, details]", projectionError.getMessage());
AwsException allAttributes = assertThrows(AwsException.class,
() -> DynamoDbAccessPathValidator.validateGsiProjection(
table, gsiPath, "ALL_ATTRIBUTES", null, null, null));
assertEquals("One or more parameter values were invalid: Select type ALL_ATTRIBUTES is not supported "
+ "for global secondary index status-index because its projection type is not ALL",
allAttributes.getMessage());
assertDoesNotThrow(() -> DynamoDbAccessPathValidator.validateGsiProjection(
table, lsiPath, "ALL_ATTRIBUTES", null, null, null));
}
@Test
void listsTheUnprojectedGsiAttributesOnceInRequestOrder() {
ObjectNode names = mapper.createObjectNode();
names.put("#q", "qq");
AwsException error = assertThrows(AwsException.class,
() -> DynamoDbAccessPathValidator.validateGsiProjection(
table, gsiPath, null, "zz.a, #q, zz.b, aa[0], pk", null, names));
assertEquals("One or more parameter values were invalid: Global secondary index "
+ "status-index does not project [zz, qq, aa]", error.getMessage());
}
@Test
void rejectsTableAllProjectedAttributesAndInvalidSelectProjectionCombination() {
assertThrows(AwsException.class, () -> DynamoDbAccessPathValidator.validateSelection(
@@ -205,6 +205,19 @@ class DynamoDbConditionKeysTest {
assertTrue(result.attributes().contains("PK"), result.attributes().toString());
}
@Test
void getItemLeavesAProjectionWithAListIndexRootUnresolved() {
DynamoDbConditionKeys.Result result = DynamoDbConditionKeys.extract(
"dynamodb:GetItem",
json("""
{"TableName":"FgacTable",
"Key":{"PK":{"S":"USER_alice"},"SK":{"S":"profile"}},
"ProjectionExpression":"email, [0]"}"""),
table);
assertEquals(List.of("PK", "SK"), result.attributes());
}
@Test
void putItemCollectsLiteralAttributeNamesFromAConditionExpression() {
DynamoDbConditionKeys.Result result = DynamoDbConditionKeys.extract(
@@ -729,6 +729,24 @@ class DynamoDbPartiQLEdgeCaseIntegrationTest {
.body("Items.sk.S", containsInAnyOrder("s1"));
}
@Test
@Order(31)
void checksSelectedColumnsAgainstAGsiProjectionAfterTheWhereClause() {
String select = "SELECT zz.a, zz.b, aa FROM \"partiql-edge-cases-index\".\"gsi-inc\"";
statement(select)
.statusCode(400)
.body("message", equalTo("One or more parameter values were invalid: "
+ "Global secondary index gsi-inc does not project [zz, aa]"));
statement(select + " WHERE gsiPk='y' AND yy='1'")
.statusCode(400)
.body("message", equalTo("One or more parameter values were invalid: Secondary index gsi-inc"
+ " does not project one or more filter attributes: [yy]"));
statement(select + " WHERE gsiPk = 1")
.statusCode(400)
.body("message", equalTo("Key attribute's data type should match its data type in table's schema: Key gsiPk"));
}
private static ValidatableResponse getItem(String pk) {
return request("DynamoDB_20120810.GetItem", """
{"TableName":"%s","Key":{"pk":{"S":"%s"},"sk":{"S":"1"}},"ConsistentRead":true}