fix(dynamodb): refuse a PartiQL key read whose filter names a key (#8559)

A PartiQL read by key now refuses the statement once the filter of
every read names a key of the table or index read, as DynamoDB does,
answering "Filter Expression can only contain non-primary key
attributes" with a key from the last read in key order. A statement
that tests a key in a way no key condition can hold is still read as a
scan and accepted, and size() on a key counts only on its own. Query
and PartiQL build that message in one place.
This commit is contained in:
TATSUNO “Taz” Yasuhiro authored and GitHub committed 2026-11-16 09:09:46 -04:00
1 parent a115078c48
commit 651ac1cbe7
4 files changed
+71 -5

No files matched your search

@@ -858,6 +858,39 @@ class DynamoDbPartiQLEdgeCaseIntegrationTest {
.statusCode(200);
}
@Test
@Order(34)
void refusesAKeyReadWhoseFilterNamesAKey() {
String select = "SELECT sk FROM " + QUOTED_TABLE + " WHERE ";
String refused = "Filter Expression can only contain non-primary key attributes: Primary key attribute: ";
for (String where : List.of("pk='ranges' AND (NOT sk='1' OR flag='one')",
"pk='ranges' AND NOT (sk='1' AND flag='one')",
"pk='ranges' AND NOT NOT sk='1'",
"pk='ranges' AND NOT size(sk) = 1",
"pk='ranges' AND (size(sk) = 1 OR flag='one')",
"pk IN ['ranges','ranges-other'] AND (NOT sk='1' OR flag='one')",
"pk='ranges' AND (NOT pk='ranges-other' OR NOT sk='1')",
"pk='ranges' AND ((sk='1' AND NOT size(sk) = 1) OR (sk='2' AND NOT size(sk) = 1))",
"(pk='ranges' AND NOT size(pk) = 1) OR (pk='ranges-other' AND NOT size(sk) = 1)")) {
statement(select + where).statusCode(400).body("message", equalTo(refused + "sk"));
}
for (String where : List.of("pk='ranges' AND (NOT pk='ranges-other' OR flag='one')",
"pk='ranges' AND ((sk='1' AND NOT size(sk) = 1) OR (sk='2' AND NOT size(pk) = 1))",
"pk='ranges' AND ((sk='2' AND NOT size(pk) = 1) OR (sk='1' AND NOT size(sk) = 1))")) {
statement(select + where).statusCode(400).body("message", equalTo(refused + "pk"));
}
for (String where : List.of("pk='ranges' AND NOT sk='1'",
"pk='ranges' AND size(sk) = 1",
"pk='ranges' AND (sk<>'1' OR flag='one')",
"(pk='ranges' AND (NOT sk='1' OR flag='one')) OR (pk='ranges-other' AND flag='two')",
"pk='ranges' AND ((sk='1' AND NOT size(sk) = 1) OR sk='2')",
"pk='ranges' AND ((sk='1' AND flag='one') OR (sk='2' AND NOT size(sk) = 1))",
"NOT sk='1' OR flag='one'")) {
statement(select + where).statusCode(200);
}
}
private static void putItem(String pk, String attributes) {
putItem(pk, "1", attributes);
}