mirror of
https://github.com/floci-io/floci.git
synced 2026-11-26 23:29:28 -05:00
fix(dynamodb): refuse a PartiQL EXISTS outside a transaction right after the syntax check (#7764)
This commit is contained in:
1 parent
c44a8722f8
commit
d0b50384fc
5 files changed
+68
-8
No files matched your search
@@ -38,8 +38,7 @@ class DynamoDbPartiQLHandler {
|
||||
case Stmt.Insert s -> executeInsert(s, region);
|
||||
case Stmt.Update s -> executeUpdate(s, ctx.returnValuesOnConditionCheckFailure(), region);
|
||||
case Stmt.Delete s -> executeDelete(s, ctx.returnValuesOnConditionCheckFailure(), region);
|
||||
case Stmt.Exists ignored -> throw new AwsException("ValidationException",
|
||||
"EXISTS can only be used in ExecuteTransaction write requests.", 400);
|
||||
case Stmt.Exists ignored -> throw new IllegalStateException("EXISTS is parsed only in a transaction");
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -156,7 +156,7 @@ public class DynamoDbPartiQLParser {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return parse(statement, List.of()).table();
|
||||
return parse(statement, List.of(), true).table();
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
List<Token> tokens = tokenize(statement.trim());
|
||||
@@ -491,15 +491,19 @@ public class DynamoDbPartiQLParser {
|
||||
}
|
||||
|
||||
static Stmt parse(String statement, List<JsonNode> parameters) {
|
||||
return parse(statement, parameters, false);
|
||||
}
|
||||
|
||||
static Stmt parse(String statement, List<JsonNode> parameters, boolean transaction) {
|
||||
try {
|
||||
return parseStatement(statement, parameters);
|
||||
return parseStatement(statement, parameters, transaction);
|
||||
} catch (StackOverflowError expected) {
|
||||
// DynamoDB answers a statement nested too deep for its parser the same way, with no message.
|
||||
throw new AwsException("InternalFailure", null, 500);
|
||||
}
|
||||
}
|
||||
|
||||
private static Stmt parseStatement(String statement, List<JsonNode> parameters) {
|
||||
private static Stmt parseStatement(String statement, List<JsonNode> parameters, boolean transaction) {
|
||||
parameters.forEach(DynamoDbAttributeValueValidator::validate);
|
||||
DynamoDbPartiQLParser parser = new DynamoDbPartiQLParser(statement, parameters);
|
||||
Stmt stmt = parser.parseStmt();
|
||||
@@ -509,6 +513,10 @@ public class DynamoDbPartiQLParser {
|
||||
if (parser.peek().type() != TType.EOF) {
|
||||
throw validationEx(UNEXPECTED_TOKEN);
|
||||
}
|
||||
// Outside a transaction DynamoDB refuses EXISTS before it checks anything inside it.
|
||||
if (stmt instanceof Stmt.Exists && !transaction) {
|
||||
throw validationEx("EXISTS can only be used in ExecuteTransaction write requests.");
|
||||
}
|
||||
if (parser.fromClauseError != null) {
|
||||
throw validationEx(parser.fromClauseError);
|
||||
}
|
||||
|
||||
@@ -4200,7 +4200,7 @@ public class NativeDynamoDbJsonHandler {
|
||||
JsonNode s = stmts.get(i);
|
||||
List<JsonNode> parameters = toPartiQLParams(s.path("Parameters"));
|
||||
statements.add(inTransactStatement(i,
|
||||
() -> DynamoDbPartiQLParser.parse(s.path("Statement").asText(), parameters)));
|
||||
() -> DynamoDbPartiQLParser.parse(s.path("Statement").asText(), parameters, true)));
|
||||
}
|
||||
long reads = statements.stream().filter(DynamoDbPartiQLParser.Stmt.Select.class::isInstance).count();
|
||||
if (reads > 0 && reads < statements.size()) {
|
||||
|
||||
Reference in new issue
Block a user