Repository navigation
fix(core): give the document path text for a list index past the end - #1226
LeeroyHannigan wants to merge 3 commits into
Conversation
A SET or ADD path can go through a list index past the end of the list. When more path elements follow that index, ExtendDB answered "The provided expression refers to an attribute that does not exist in the item". DynamoDB answers "The document path provided in the update expression is invalid for update". A path through a missing map key already gets that text. Each request was measured twice in us-east-1 on 20 Nov 2026. UpdateItem answers the document path text for SET k[5].x, ADD k[5].x and SET k[5][0], where k holds two elements. ExecuteStatement and BatchExecuteStatement answer it for SET k[5].x, and TransactWriteItems cancels with it as a ValidationError reason. With the index last, SET k[5] still appends the value. set_nested and navigate_to_parent_map_or_create now let an index past the end reach the arm that returns the document path text. A BatchExecuteStatement now charges such a statement the write units of its item, as DynamoDB does. Fixes #1216.
#596 rewrote the ADD path walk as `navigate_to_existing_parent_map`, which answers an index past the end with the document path text. The merge takes main's function, so this branch keeps only its SET change in `set_nested`.
#596 merged first with `update_add_parent_tests.rs`, which sends `ADD l[5].a :one` and expects the document path text. The ADD row of `a_path_through_a_list_index_past_the_end` sent the same shape, so it goes, and the test keeps the SET rows that this PR changes.
navareamol
left a comment
There was a problem hiding this comment.
I think the cost claim has no test. The description says the batch row (SET a = 9 on another item, then SET k[5].x = 1) now costs 2.0. That comes from is_charged_failure in batch.rs, which charges a failed update only when its text is in UPDATE_FAILURES, so it moves with this change. On SQLite at 63d4a1d the batch reports 2.0, and on main 1.0. The two rows you added go to test_an_error_of_the_item_operation_names_the_table, which does not read ConsumedCapacity, and test_a_failed_write_is_charged_on_its_table has a document path row only for SET a.b = 1. Could you add a row there whose second statement is SET l[5].x = 1 on an item that holds a short list l, next to the document-path row? cap-ok2 holds no l, so the row needs its own item, or main would already give the document path text for it. The ExecuteStatement and TransactWriteItems rows of the table have no wire test either. They pass on SQLite here, so a row for each would keep them.
The comment on the new rows says they were measured "on a table keyed on pk alone, after a statement that succeeds", but the test sends one statement to gtable, which has pk, sk and a GSI. The description says DynamoDB gave both answers in the form the test sends them. Which one is right? If the second, could you update the comment?
A question, not a condition: the update evaluates each SET value and then its path, clause by clause. Here SET k[5].x = :v, a = zz answers the document path text, but SET a = zz, k[5].x = :v answers that the attribute does not exist. Did you measure the second order on DynamoDB?
I will approve once the 2.0 charge has a test row and the comment on the new rows matches what was measured.
What
A SET or ADD path can go through a list index past the end of the list and continue after it. ExtendDB answered such a path with
The provided expression refers to an attribute that does not exist in the item. DynamoDB answersThe document path provided in the update expression is invalid for update.The change is in
crates/core/src/expression/update_evaluator.rs. The index arm ofset_nested(SET) now sends an index past the end to the existing arm with the document path text. This change deletes the branch that wrote the absent attribute text for it. #596 made the same change for ADD innavigate_to_existing_parent_map, which main now has. An index past the end as the last element of a SET path still appends the value.Why
DynamoDB's answers, measured in us-east-1 on 20 November 2026 on an item whose
kis[4, 5]andmis{"x": 1}. Each request went out twice and got the same answer both times.:vis{"N": "1"}.SET k[5].x = :vADD k[5].x :vSET k[5][0] = :vADD k[5][0] :vSET k[5].x = :v, a = zzUPDATE "<table>" SET k[5].x = 1 WHERE pk = 'em-upd-operand'SET k[5].x = :vTransactionCanceledException, aValidationErrorreason with the document path textSET a = 9on another item, thenSET k[5].x = 1CapacityUnits2.0, the second response with the document path textSET k[5] = :vkbecomes[4, 5, 1]SET m.q.x = :vWith this change, ExtendDB answers each row with DynamoDB's text. Since #596 merged, main already gives the two UpdateItem ADD rows that answer. The batch row now costs 2.0 as on DynamoDB, because the batch charges a failed UPDATE with the document path text.
Fixes #1216
Testing done
cargo test -p extenddb-core --lib: 1147 passed.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.cargo +1.91.1 check -p extenddb-core --libpasses, so theif letchain of the ADD arm builds on the minimum Rust version.a_path_through_a_list_index_past_the_endholds three of the refused UpdateItem paths:SET k[5].x,SET k[5][0]andSET m.q.x.update_add_parent_tests.rsfrom UpdateExpression ADD creates no missing map on its path #596 holds the ADD form. With the change reverted, the test fails.tests/test_partiql_batch.py,tests/test_partiql_item_depth.py,tests/test_partiql_write.py,tests/test_index_key_validation_on_update.pyandtests/test_item_operations.pypassed 702 tests, with 3 expected failures.test_an_error_of_the_item_operation_names_the_tableintests/test_partiql_batch.py: a path through an index past the end, and a value read at one. DynamoDB gave both answers in the form the test sends them. The first row fails against a server built from main. The test's item now holds a listl, and DynamoDB gives the other 13 rows of the test the answers they expect with it.Line counts over main after the merge: production +3 -9, tests +44 -2.
Merge of 25 November
#596 merged first.
259f3a851mergesmainata417b2f82and takes #596'snavigate_to_existing_parent_map, which answers an ADD path through an index past the end with the document path text.63d4a1d88drops the ADD row of this PR's unit test, because #596's test sends the same shape. At63d4a1d88,cargo test -p extenddb-core --libpassed 1167 tests, andcargo fmt --checkis clean. At the merge,cargo test -p extenddb-wasm-adapterpassed its 3 unit tests and the parity corpus, andcargo check -p extenddb-engine --no-default-features --liband clippy with-D warningson core are clean. The cargo commands ran with--locked.Not in this PR:
SET a = 9, thenSET a = k[5]costs 1.0, where DynamoDB charges 2.0 (BatchExecuteStatement: an UPDATE that fails on an absent attribute is not charged, where DynamoDB charges its write unit #1178, open PR fix(engine): charge a batch UPDATE that refers to an absent attribute #1217).TransactionCanceledExceptionbody carries its text undermessageand writes__typeafterCancellationReasons(TransactionCanceledException and IdempotentParameterMismatchException carrymessage; DynamoDB sendsMessage, and the token mismatch text differs #760 and An error body lists its members in name order, so CancellationReasons comes before __type, where DynamoDB writes __type first #1222).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.