Files
floci/src/main/java/io/github/hectorvent
Benson 6b2c081f0b fix(dynamodb): correct UpdateExpression semantics and TransactWriteItems idempotency (#804)
Three related DynamoDB correctness fixes, all in the same DynamoDbService surface:

1. Cross-attribute SET reads pre-update values (#798)
   "SET a = :v, b = a" now writes the *original* value of `a` into `b`, matching
   real DynamoDB. Snapshot the item once at the start of applySetClause and
   resolve every RHS reference against the snapshot; defer writes to `item`.
   Previously, in-place mutation between comma-separated clauses caused later
   clauses to read post-update values, silently corrupting audit/history fields.

2. ClientRequestToken idempotency for TransactWriteItems (#799)
   Same token + same body → no-op success. Same token + different body →
   IdempotentParameterMismatchException. Implemented via a per-region in-memory
   cache with a 10-minute TTL (matching the AWS window) keyed by
   "region::token" with a SHA-256 of the raw request body for comparison.
   handleTransactWriteItems now extracts ClientRequestToken from the request
   and forwards it plus the raw body through a new 4-arg
   transactWriteItems(items, region, token, rawRequest) overload. The original
   2-arg signature is preserved as a no-token convenience that delegates.

3. Parenthesized arithmetic in SET silently dropped (#802)
   "SET c = (c - :v)" now applies identically to "SET c = c - :v". Added
   stripOuterParens() and call it on each SET-action RHS before
   findArithmeticOperator() — which still correctly only finds operators at
   depth 0, but now sees an unwrapped expression to scan. Combined forms like
   "SET c = (if_not_exists(c, :d) - :v), other = :s" now apply both clauses
   instead of dropping the parenthesized one while applying the other.

Tests
- DynamoDbServiceTest gains 8 regression tests:
  cross-attribute SET (plain + #name), parenthesized arithmetic (simple,
  with if_not_exists, doubled parens, alongside a plain assignment), and
  TransactWriteItems idempotency (no-op replay, parameter-mismatch error,
  null-token bypass).

Refs: #798, #799, #802
2026-05-13 00:38:56 -05:00
..