fix(dynamodb): tolerate whitespace before a function's own parenthesis (#2510)

applySetClause/evaluateSetExpr gated list_append and if_not_exists on a
literal startsWith(functionName + "("), so "list_append (x, y)" (space
before the parenthesis) fell through to the "plain attribute reference"
branch instead of being recognized as a function call. The SET then
silently resolved to no value and left the target attribute unchanged -
no exception, no error, just a dropped write.

Real AWS DynamoDB's UpdateExpression grammar is whitespace-insensitive
around function calls, and this is exactly the form PynamoDB (a widely
used Python DynamoDB ORM) always emits, so this reliably data-loses
every list_append done through PynamoDB.

#1640 already fixed whitespace normalization between clause keywords and
between a function's arguments; this closes the remaining gap between a
function's name and its own opening parenthesis, which sits in a
different code path (the per-clause value evaluator, not the top-level
tokenizer) and wasn't covered by that fix's tests.

Fixes #2509
This commit is contained in:
Kumar Prabhat authored and GitHub committed 2026-08-25 23:48:06 -05:00
1 parent 859db2f352
commit e4b101d5da
2 files changed
+45 -3

No files matched your search

@@ -159,6 +159,36 @@ class DynamoDbUpdateExpressionWhitespaceTest {
.body("Attributes.c.N", equalTo("6"));
}
/**
* Regression test for #2509: a space between a function name and its own opening
* parenthesis (e.g. {@code "list_append ("} rather than {@code "list_append("}) is
* accepted by real AWS and is exactly what PynamoDB always emits, but
* {@code applySetClause}/{@code evaluateSetExpr} gated on a literal
* {@code startsWith(functionName + "(")} check, so the spaced form fell through to the
* "plain attribute reference" branch and silently failed to resolve - the SET was a
* no-op with no error. Distinct from #1640 above: this whitespace sits between the
* function name and its own parenthesis, not between clause keywords or a function's
* arguments, so #1640's tokenizer-level normalization didn't reach it.
*/
@Test
void spaceBeforeFunctionParenthesisIsAccepted() {
createAndSeed("UpdWsFuncSpace", """
{"pk":{"S":"x"},"l":{"L":[{"S":"one"}]},"m":{"S":"present"}}""");
given().header("X-Amz-Target", "DynamoDB_20120810.UpdateItem").contentType(CT).body("""
{"TableName":"UpdWsFuncSpace","Key":{"pk":{"S":"x"}},
"UpdateExpression":"SET #l = list_append (#l, :more), #m = if_not_exists (#missing, :fallback)",
"ReturnValues":"ALL_NEW",
"ExpressionAttributeNames":{"#l":"l","#m":"m","#missing":"missing"},
"ExpressionAttributeValues":{":more":{"L":[{"S":"two"}]},":fallback":{"S":"unused"}}}
""")
.when().post("/").then()
.statusCode(200)
.body("Attributes.l.L.size()", equalTo(2))
.body("Attributes.l.L[0].S", equalTo("one"))
.body("Attributes.l.L[1].S", equalTo("two"))
.body("Attributes.m.S", equalTo("unused"));
}
@Test
void invalidLeadingKeywordIsStillRejected() {
createAndSeed("UpdWsBad");