Skip to content

fix(core): report the first failing operand of +, - and list_append - #1180

Open
LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/1034-update-operand-order
Open

LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/1034-update-operand-order

Conversation

@LeeroyHannigan

Copy link
Copy Markdown
Collaborator

What

ExtendDB now checks the type of each operand of +, - and list_append before it evaluates the next operand, as DynamoDB does. So the first operand that fails is the one it reports. On an item where s is a string and z is absent, SET a = s + z now gets An operand in the update expression has an incorrect data type. Before this change, ExtendDB evaluated both operands first and answered The provided expression refers to an attribute that does not exist in the item.

In crates/core/src/expression/update_evaluator.rs, the Expr::Arithmetic arm of evaluate_set_value and the list_append arm of evaluate_set_function check each operand right after its evaluation. The new operand_type_error writes the operand type text for these three. The arithmetic now sits in the Expr::Arithmetic arm, 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 attribute z. TYPE is the operand type text and ABSENT the absent attribute text.

Request DynamoDB ExtendDB before
UpdateItem SET a = s + z TYPE ABSENT
UpdateItem SET l = list_append(s, z) TYPE ABSENT
UpdateItem SET a = s - z TYPE ABSENT
UpdateItem SET a = s + m.q TYPE ABSENT
UpdateItem SET a = z + s ABSENT ABSENT
UpdateItem SET a = n + z ABSENT ABSENT
UpdateItem SET l = list_append(k, z) ABSENT ABSENT
UpdateItem SET a = s + z on a key with no item ABSENT ABSENT
UpdateItem SET a = s + :v and SET l = list_append(s, :l) TYPE TYPE
TransactWriteItems, one Update SET a = s + z TransactionCanceledException, the reason ValidationError with TYPE the reason with ABSENT
TransactWriteItems, one Update SET a = z + s the reason with ABSENT the reason with ABSENT
ExecuteStatement UPDATE ... SET a = s + z TYPE ABSENT
ExecuteStatement UPDATE ... SET a = z + s ABSENT ABSENT

In a BatchExecuteStatement with "ReturnConsumedCapacity": "TOTAL", the statements SET a = 9 on another item and SET a = s + z cost 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 warnings and cargo +1.97.0 fmt --all -- --check are clean.
  • Against ExtendDB on SQLite, the new tests/test_update_operand_order.py passed 14 tests. test_partiql_forms.py, test_partiql_batch.py, test_partiql_write.py and test_index_key_validation_on_update.py passed 609.
  • With update_evaluator.rs from main, the core test fails on SET a = s + z.
  • The last change cut lines and changed no answer. On the commit before it, cargo test -p extenddb-server --lib passed 513 tests, and the wire files passed 2064 tests in tests/ and 116 in tests/python. The 5 backup_store tests that check file permissions fail on the test host, where a parent directory belongs to another user. This PR does not change backup_store.rs.

Line counts: production +26 -31. Tests +152. update_evaluator.rs is 668 lines, 673 on main.

Not in this PR, each in an open issue or PR:

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

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, 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.

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 navareamol left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UpdateItem SET a = s + z, with s a string and z absent, answers the absent attribute text, where DynamoDB answers the operand type text

2 participants