fix: SET snapshot semantics and parenthesised arithmetic#158
Conversation
|
This creates mutual recursion (parse_set_operand → parse_value_expr → parse_set_operand) without a depth limit. Deeply nested parens like SET c = ((((((c - :v)))))) would recurse unboundedly. In practice, DynamoDB's 4KB expression limit caps nesting at ~1000 levels, which shouldn't blow the stack on most systems. The condition parser has a 150-depth limit for reference. Should we do the same here? |
5c88ecd to
64254a1
Compare
Good catch on both fronts. Updated: This also eliminates the unbounded recursion concern, since |
| } | ||
|
|
||
| #[test] | ||
| fn single_parens_accepted() { |
There was a problem hiding this comment.
If you wanted bonus points, could check for error on unmatched parens.
jcshepherd
left a comment
There was a problem hiding this comment.
One suggestion for an additional unit test but looks good otherwise.
Adds the unit tests suggested on #158: an opening paren with no matching close, and a stray closing paren, must each raise ValidationException rather than panic or be silently accepted.
What
Fix two UpdateItem expression evaluation bugs:
SET snapshot semantics: Multiple SET clauses now evaluate their RHS against the pre-update item snapshot. Previously
SET a = :v, b = awould assignbthe new value ofainstead of the original.Parenthesised arithmetic:
SET c = (c - :v)now parses correctly. The SET value parser previously rejected(as an unexpected token.Why
DynamoDB evaluates the entire UpdateExpression against a single pre-update snapshot, no SET clause can observe the effect of another SET clause in the same request. This is documented behavior that applications rely on (e.g., swap patterns like
SET a = b, b = a).Parenthesised arithmetic is valid DynamoDB syntax and used by SDKs and ORMs that defensively wrap expressions.
Testing done
cargo fmt --all -- --check— cleancargo clippy --all-targets -- -D warnings— cleancargo test --workspace— all pass (2 new unit tests)tests/test_set_evaluation.py— 3 integration tests (snapshot semantics, subtraction in parens, addition in parens), all pass against ExtendDBChecklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, or public CLI surface, an RFC has been accepted or is linked
below. Otherwise, an ADR captures the decision (link below).
ADR / RFC: n/a
By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.