Repository navigation
fix(core): report the first failing operand of +, - and list_append - #1180
LeeroyHannigan wants to merge 1 commit into
Conversation
DynamoDB checks the type of each operand of +, - and list_append once it has its value, before it reads the next operand. On an item where s is a string and z is absent, SET a = s + z fails on s. DynamoDB answers "An operand in the update expression has an incorrect data type". ExtendDB answered "The provided expression refers to an attribute that does not exist in the item". SET a = s - z, SET a = s + m.q and SET l = list_append(s, z) differed in the same way. ExtendDB read both operands and only then checked their types. It now checks the type of each operand before it evaluates the next one. One place writes the operand type text for +, - and list_append. TransactWriteItems and ExecuteStatement UPDATE now give the answers DynamoDB gives. Measured in us-east-1 on 2026-11-14, 2026-11-16 and 2026-11-19. Fixes #1034.
navareamol
left a comment
There was a problem hiding this comment.
I think the early return changes one more answer than the table shows. The undefined value check happens only when a placeholder is resolved during evaluation, and the new let ... else { return Err(operand_type_error()) } returns before the right operand is resolved. On SQLite, SET a = s + :undef with no ExpressionAttributeValues answers Invalid UpdateExpression: An expression attribute value used in expression is not defined; attribute value: :undef on main and An operand in the update expression has an incorrect data type with this PR. SET l = list_append(s, :undef) changes the same way. Has anyone measured what DynamoDB answers for these two? If it answers the undefined value text, one option is to check that every value placeholder in the UpdateExpression is defined before evaluation, next to the unused check in resolver.rs. That would also change SET a = z + :undef, which answers the absent attribute text on main and here.
The description says the BatchExecuteStatement in the Why section costs 1.0 on main and 2.0 with this PR. I measured the same on SQLite (CapacityUnits 1.0 with main's update_evaluator.rs, 2.0 with this PR), but no test pins it, and batch.rs charges by matching the message text, so a later message change would move the charge with nothing failing. Could you add that batch to test_update_operand_order.py or test_partiql_batch.py?
Two cases change here that are not in the table: SET b = s + z, c = z and SET a = if_not_exists(z, s) + z answered the absent attribute text on main and now answer the operand type text. Was the two action case measured? It also depends on DynamoDB evaluating the SET actions in order.
The branch is 49 commits behind main. It merges cleanly and the merged tree passes the core and engine lib tests and the wire file. Some numbers in the description are from the old base: update_evaluator.rs is 659 lines on main now, and #596 is merged.
I will approve once the undefined placeholder answer is measured (and fixed if it differs) and the batch charge has a test.
What
ExtendDB now checks the type of each operand of
+,-andlist_appendbefore it evaluates the next operand, as DynamoDB does. So the first operand that fails is the one it reports. On an item wheresis a string andzis absent,SET a = s + znow getsAn operand in the update expression has an incorrect data type. Before this change, ExtendDB evaluated both operands first and answeredThe provided expression refers to an attribute that does not exist in the item.In
crates/core/src/expression/update_evaluator.rs, theExpr::Arithmeticarm ofevaluate_set_valueand thelist_appendarm ofevaluate_set_functioncheck each operand right after its evaluation. The newoperand_type_errorwrites the operand type text for these three. The arithmetic now sits in theExpr::Arithmeticarm, in the same order: the type of each operand, then the range of each. UpdateItem, TransactWriteItems and the PartiQL UPDATE of ExecuteStatement all run this code.Why
These are DynamoDB's answers, measured in us-east-1 on 14, 16 and 19 November 2026. Each request went out at least twice and got the same answer every time, and DynamoDB left the item as stored. The item is
{"pk": {"S": "em-upd-operand"}, "n": {"N": "10"}, "k": {"L": [{"N": "4"}, {"N": "5"}]}, "m": {"M": {"x": {"N": "1"}}}, "s": {"S": "str"}}, with no attributez. TYPE is the operand type text and ABSENT the absent attribute text.SET a = s + zSET l = list_append(s, z)SET a = s - zSET a = s + m.qSET a = z + sSET a = n + zSET l = list_append(k, z)SET a = s + zon a key with no itemSET a = s + :vandSET l = list_append(s, :l)SET a = s + zTransactionCanceledException, the reasonValidationErrorwith TYPESET a = z + sUPDATE ... SET a = s + zUPDATE ... SET a = z + sIn a BatchExecuteStatement with
"ReturnConsumedCapacity": "TOTAL", the statementsSET a = 9on another item andSET a = s + zcost 2.0 units on DynamoDB. They cost 1.0 on main and 2.0 with this PR. ExtendDB charges a failed UPDATE that gets TYPE, and the second statement now gets TYPE.Closes #1034
Testing done
cargo test -p extenddb-core --lib: 1147 passed, 1 ignored.cargo test -p extenddb-engine --lib: 870 passed.cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warningsandcargo +1.97.0 fmt --all -- --checkare clean.tests/test_update_operand_order.pypassed 14 tests.test_partiql_forms.py,test_partiql_batch.py,test_partiql_write.pyandtest_index_key_validation_on_update.pypassed 609.update_evaluator.rsfrom main, the core test fails onSET a = s + z.cargo test -p extenddb-server --libpassed 513 tests, and the wire files passed 2064 tests intests/and 116 intests/python. The 5backup_storetests that check file permissions fail on the test host, where a parent directory belongs to another user. This PR does not changebackup_store.rs.Line counts: production +26 -31. Tests +152.
update_evaluator.rsis 668 lines, 673 on main.Not in this PR, each in an open issue or PR:
SET a = :s + zandSET l = list_append(:s, z), with:sa string, get a refusal from DynamoDB before it reads the item. With this PR, ExtendDB answers TYPE, and main answers ABSENT. fix(expressions): validate in the service's order, with its messages #399 adds that check. It also refuses alist_appendinside alist_append, as DynamoDB does.SET a = s + (z + :v)andSET a = (z + :v) + sare evaluated, where DynamoDB refuses a sum in parentheses as an operand with a syntax error #1177: DynamoDB refuses a sum in parentheses as an operand, such ass + (z + :v), with a syntax error. ExtendDB evaluates it.Other open PRs: #890 and #596 rewrite the DELETE and ADD paths of the same file. Those paths keep their own copies of the operand type text. #590 changes the same file too. This PR merges with each of them, with #399 and with every other open PR without a conflict.
Checklist
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.