Skip to content

fix(core): refuse overlapping and conflicting UpdateExpression paths - #1543

Open
eliseong wants to merge 3 commits into
mainfrom
eliseong-update-path-conflict-2026-12-01
Open

eliseong wants to merge 3 commits into
mainfrom
eliseong-update-path-conflict-2026-12-01

Conversation

@eliseong

@eliseong eliseong commented Dec 1, 2026 •

Copy link
Copy Markdown
Collaborator

What

UpdateItem and a TransactWriteItems Update now refuse an UpdateExpression whose document paths meet. Two paths meet when they are equal step by step until one ends (they overlap, as in SET a = :b, a.b = :z) or until a step where one names a map member and the other a list index (they conflict, as in SET a.b = :b, a[0] = :z). The service answers:

ValidationException: 1 validation error detected: Invalid UpdateExpression: Two document paths conflict with each other; must remove or rewrite one of these paths; path one: [a, b], path two: [a, [0]]

with overlap in place of conflict for an overlap. TransactWriteItems gives the same text without 1 validation error detected: . Nothing is written.

validate_update_paths in crates/core/src/expression/resolver.rs compares the paths of all four clauses in expression order, after #name resolution. Path one is the last path that meets a later path, and path two is the earliest later path that it meets. On the service, overlap and conflict are one check: SET a.b = :b, a[0] = :z, a = :b answers the overlap [a, [0]], [a], and SET a = :b, a.b = :b, a[0] = :z answers the conflict [a, b], [a, [0]].

The service names an undefined #name or :value ahead of the paths. validate_update_refs reads the ConditionExpression and then each action, its path and then its value, and refuses the first undefined reference in that order, names and values alike, with the Invalid ConditionExpression: or Invalid UpdateExpression: prefix. UpdateItem and a TransactWriteItems Update run it just ahead of the path check.

The update path check and the PartiQL overlap check share the classifier paths_meeting. Those two and the ProjectionExpression overlap check share the message paths_meet_message, in crates/core/src/expression/projection.rs. The upgrade manual lists the change under v1.2.0.

On main, ExtendDB did not compare the paths. It applied an overlap or a conflict whose actions all fit the stored value, such as REMOVE a.b, a.b or REMOVE a.b, a[0] on a map, and answered any other with The document path provided in the update expression is invalid for update from the action that did not fit.

Why

Closes #811

Testing done

  • DynamoDB in us-east-1 on 25 November 2026: 23 UpdateItem shapes, numbered 1 to 23. Shape 3 was sent against three item states (a a list, a absent, no item), so the shapes make 25 UpdateItem rows. A TransactWriteItems Update was sent for 5 of the shapes. Each request was sent twice and got the same answer both times. Every refused request left the item unchanged.
  • On those rows, a local SQLite server built from this branch gives the service's answer on 20 of the 25 UpdateItem rows and on 5 of the 5 TransactWriteItems rows. main gives it on 1 and 0. The 5 UpdateItem rows that still differ are listed under Notes.
  • 147 request cells sent to DynamoDB on 1 December 2026, each twice: 62 UpdateItem, 62 TransactWriteItems with one Update, and 23 TransactWriteItems with two items. They combine a path fault with other faults: a syntax error, a reserved word, nesting and size limits, an unreadable number, undefined and unused names and values, a missing table, an empty key and a key update. The branch gives the service's answer on 41 cells and main on 21. The branch gives the service's answer on every cell that main does.
  • About 130 further request shapes sent to DynamoDB on 4 December 2026, each twice, with undefined references inside functions, BETWEEN, IN, NOT and nested parentheses, and beside the other faults above. No shape that main answers as the service does is answered differently by this branch.
  • tests/test_update_expression_paths.py (new, dual-target): 15 passed against DynamoDB and against this branch. On main, 14 of the 15 fail.
  • update_paths_answer_as_the_service pins the kind and both paths for 17 shapes. update_paths_accept_siblings checks 5 shapes the service accepts, among them a name that holds a dot and a path on the right side of SET. update_refs_name_the_first_undefined_reference checks 8 shapes.
  • The PartiQL and ProjectionExpression overlap wire tests give the same answers as on main.
  • cargo fmt --all -- --check, cargo test -p extenddb-core --lib (1263 passed) and cargo test -p extenddb-engine --lib (981 passed). cargo clippy -p extenddb-core -p extenddb-engine --all-targets -- -D warnings is clean apart from the unused line_len in crates/core/tests/data_file_decode_peak.rs on macOS, which main has too.

Notes

The rows that still differ from the service. main gives the same answer on each:

  • UpdateItem checks unused names and values ahead of the undefined references and the paths, and the service checks them after. So SET a.b = :b, a[0] = :z with an unused value answers the unused value, where the service answers the conflict. These are 25 November cases 6, 10, 18 and 23. TransactWriteItems answers these as the service does.
  • An undefined #name in the path of an update action is refused by an earlier check of each handler. On UpdateItem that check reads every step of the path and answers without 1 validation error detected: and without Invalid UpdateExpression: , as in case 19. On TransactWriteItems it reads the first step of the path and answers without the prefix. On both operations it names that #name ahead of a reference that the service names first, as in SET #u = :b with the condition attribute_exists(#q).
  • On TransactWriteItems, the key attribute check and the table lookup run ahead of the undefined references, where the service checks the references first.

Moving these checks also moves the nesting and number checks of ExpressionAttributeValues, which the service runs first. #399 reorders those checks, so this PR leaves them in place.

The ProjectionExpression check keeps its own prefix test, is_prefix. With paths_meeting it would also refuse a conflict such as a.b, a[0]. The service refuses that conflict too, but it is a separate difference from #811, so this PR leaves the check as it is.

On the overlap with other PRs: #399 and #507 add validate_update_paths_disjoint, the overlap half of this check, and #597 and #1140 carry the same function. For SET a.b = :b, a.c = :b, a = :b the service names [a, c], [a], where the first pair in expression order is [a, b], [a], so the overlap half alone cannot answer as the service does. Whichever of this PR and #399 or #507 merges second deletes its copy of the check and that copy's tests: if this PR merges first, the other PR deletes validate_update_paths_disjoint and its tests and calls validate_update_paths; if the other merges first, this PR deletes validate_update_paths_disjoint and its tests on rebase. #399 also reorders the checks that validate_update_refs orders here, and the second of those two to merge keeps one copy.

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

Breaking changes

  • An UpdateExpression whose paths overlap or conflict is now refused, as on the service. On main an overlap, and a conflict whose actions all fit the stored value, were applied.
  • On TransactWriteItems the error code changes. An Update with an overlap, a conflict, or an undefined #name or :value now answers ValidationException, and no item of the transaction runs. On main the ones it did not apply answered TransactionCanceledException with a ValidationError reason.

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.

An UpdateExpression whose paths name one element once as a map member
and once as a list element, such as SET a.b = :b, a[0] = :z, was not
checked as a whole. ExtendDB applied the actions in turn, and the
action that did not fit the stored value failed with "The document
path provided in the update expression is invalid for update".
DynamoDB refuses the expression before it reads the item, with "Two
document paths conflict with each other". Two paths where one is a
prefix of the other, such as SET a = :b, a.b = :z, get "Two document
paths overlap with each other" the same way; ExtendDB had no check for
them either.

validate_update_paths compares the paths of all clauses in expression
order. Path one is the last path that meets a later one, and path two
is the earliest later path it meets. UpdateItem runs it before the key
attribute check, with "1 validation error detected: " ahead of the
text. A TransactWriteItems Update runs it before the unused names and
values check, with no prefix. Both keep the order of the checks that
already ran before it.

Measured in us-east-1 on 2026-11-25, each request sent twice.

Fixes #811

Signed-off-by: Elise Ong <eliseong@amazon.com>

@LeeroyHannigan LeeroyHannigan 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.

Thanks for this. I built the branch at 4723c28 and main at 6942157. On the branch, tests/test_update_expression_paths.py passes 11 of 11 tests, and on main 10 of them fail. cargo test -p extenddb-core -p extenddb-engine --lib passes 1243 and 978 tests, as the description says.

I also sent 37 request shapes to DynamoDB in us-east-1 on 1 December, each twice, with the same answer both times. The table did not exist, so a refusal ahead of the table lookup shows. They confirm the overlap and conflict texts, the TransactWriteItems text without 1 validation error detected: , and the rule that picks path one and path two. Seven of them confirm that rule on shapes where another rule names a different pair. For example, REMOVE a SET a.b = :b answers with the pair [a], [a, b], in that order. Apart from the unused value or name that the description lists, the branch gives the service's answer on every path refusal. It refuses no shape that the service accepts.

This needs two changes before it can merge:

  1. The upgrade manual needs an entry. docs/versioning.md says that a change that makes ExtendDB answer a request as DynamoDB does ships in a minor release. It also says that the upgrade manual lists each such change under Behavior Changes by Release. Main applies ADD s :ss DELETE s :ss and REMOVE a.b, a.b, and the branch refuses both, as the service does. On TransactWriteItems the error code also changes, from TransactionCanceledException with a ValidationError reason to ValidationException. 1.1.0 shipped on 27 November without this change, so the entry is the first v1.2.0: heading. Please add the TransactWriteItems change to Breaking changes too. The documentation box in the checklist has a tick, but no file under docs/ changes.
  2. The new path validation now answers ahead of an undefined value or name that the service names first. The comment on line 265 of update_item.rs has the measured rows.

The other inline comments are smaller.

On the description:

  • "23 UpdateItem shapes" and "20 of the 25 UpdateItem rows" disagree. Please give the right count, or say what each number counts.
  • "The rows that still differ are listed under Notes" leaves out the rows in the comment on line 265. In that comment's two UpdateItem rows, main names the same fault as the service, with a text that lacks the envelope or the prefix. The sentence "No cell that main answers as the service does is answered differently by this branch" is true only because of those text differences. Please list the rows.

On the overlap with other PRs: #399 (opened 14 October) adds validate_update_paths_disjoint, the overlap half of this validation. #507, #597 and #1140 carry the same function. #507 has an approval, and its base is main. This PR closes #811, which #399 does not fix, and the description credits #399 and gives a merge plan. Please name #507 beside #399 in that plan. Please also say that whichever PR merges second deletes its function and that function's tests.

Comment thread crates/engine/src/update_item.rs Outdated
// The service checks the paths ahead of the key attributes. It also
// checks them ahead of the table and of unused names and values, which
// this handler checks first.
extenddb_core::expression::validate_update_paths(&actions, &maps).map_err(|e| match e {

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.

This call now answers ahead of an undefined value or name that the service names first. Measured on 1 December, each request twice:

Request DynamoDB main branch
UpdateItem SET a.b = :q, a[0] = :z, :q not defined undefined value :q undefined value :q, without 1 validation error detected: conflict
UpdateItem SET a.b = :b, a[0] = :z, condition attribute_exists(#q), #q not defined undefined name #q, in the ConditionExpression undefined name #q, without the envelope and the prefix conflict
TransactWriteItems Update, the first row's request undefined value :q TransactionCanceledException conflict
TransactWriteItems Update, the second row's request undefined name #q, in the ConditionExpression TransactionCanceledException conflict
TransactWriteItems Update SET a = :b, a.b = :z, the same condition undefined name #q, in the ConditionExpression TransactionCanceledException, with the undefined #q as its reason overlap

On main, both faults come from evaluation, after this call: the value from update_evaluator.rs line 131, and the name from the condition evaluation. So on UpdateItem, this change replaces the fault that main and the service name. Please refuse an undefined :value of the update actions, and an undefined #name or :value of the ConditionExpression, ahead of this call and ahead of line 581 of transact_write_items.rs. The walk that validate_unused_attributes does with collect_expr_refs already collects these references. #399 also reorders these checks, so the second of the two PRs to merge keeps one copy.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 6da1a96. validate_update_refs reads the ConditionExpression and then each action, its path and then its value, and refuses the first undefined #name or :value ahead of the path check, here and in TransactWriteItems. All five rows in your table now give the service's answer, and the wire tests pin them. An undefined #name in an update path is still refused earlier by each handler, as on main; the description lists those rows. #399 also reorders these checks, so the second of the two to merge keeps one copy.

Comment thread crates/engine/src/update_item.rs Outdated
// this handler checks first.
extenddb_core::expression::validate_update_paths(&actions, &maps).map_err(|e| match e {
DynamoDbError::ValidationException(m) => {
DynamoDbError::ValidationException(format!("1 validation error detected: {m}"))

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.

Nit: extenddb_core::error::validation_errors_detected(&[m]) builds this envelope. The engine already calls it in lib.rs and streams.rs.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 6da1a96. The envelope now comes from validation_errors_detected.

},
)?;
}
extenddb_core::expression::validate_update_paths(&actions, &maps)?;

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.

An undefined #name after the first step of a path now stops here, without the Invalid UpdateExpression: prefix. This changes requests that have no path conflict. For a TransactWriteItems Update SET a.#u = :b with no ExpressionAttributeNames, DynamoDB answers Invalid UpdateExpression: An expression attribute name used in the document path is not defined; attribute name: #u. Main answers TransactionCanceledException, and the branch answers the same text without the prefix. prefix_expression_error(e, ExpressionKind::Update) gives the service's text here, as the condition check on the lines above does.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in 6da1a96. validate_update_refs refuses that name with the Invalid UpdateExpression: prefix ahead of this line, and the path check result also goes through prefix_expression_error. SET a.#u = :b now gives the service's text, and a wire test pins it. A #name at the first step of a path is still refused earlier, in validate_no_key_updates, without the prefix, as on main.

Comment thread crates/core/src/expression/resolver.rs Outdated
.collect();
let resolved = resolve_paths(&paths, maps)?;
// `Some(true)` when the paths conflict, `Some(false)` when they overlap.
let meet = |a: &[ResolvedElement], b: &[ResolvedElement]| {

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.

Main already has this classifier and this message. meeting in crates/engine/src/partiql/write/update.rs returns "conflict" for a member against an index, and "overlap" when the steps run out. first_overlap in the same file formats the same sentence, and path_list renders a path as render_path does. is_prefix and check_overlap in projection.rs give the overlap half for a ProjectionExpression. The loops can stay separate, because the three callers name different pairs. Please share one classifier and one message function, or say in the description why this copy stays.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 6da1a96. paths_meeting and paths_meet_message in projection.rs now serve validate_update_paths and the PartiQL first_overlap, and meeting and path_list are gone. check_overlap for ProjectionExpression uses paths_meet_message. It keeps is_prefix, because paths_meeting would also refuse a projection conflict such as a.b, a[0], which is a separate difference from #811; the description says so. The loops stay separate.

}

#[test]
fn update_paths_accept_siblings() {

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.

Please add two measured shapes that the service accepts and that a wrong comparison would refuse. The first is SET #d = :b, a.b = :z with #d bound to a.b, one attribute whose name contains a dot. The second is SET a = :b, b = a, with a path on the right side of SET. DynamoDB answered both with ResourceNotFoundException on a missing table, so it refused neither for its paths. With the current rows, a change that splits name values on . or compares right side paths still passes them.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added both to update_paths_accept_siblings in 6da1a96: SET #d = :b, a.b = :z with #d bound to a.b, and SET a = :b, b = a.

///
/// # Errors
///
/// Returns `DynamoDbError::ValidationException` with the `Invalid

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.

Nit: this function also returns the errors of resolve_paths unchanged: an undefined #name, with no prefix, and a path that starts with an index. Please name both in # Errors.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in 6da1a96. # Errors now names both: an undefined #name, and a path that starts with an index.

The path check answered ahead of an undefined #name or :value that
DynamoDB names first. validate_update_refs now reads the
ConditionExpression and then each update action, its path and then its
value, and refuses the first undefined reference in that order, names
and values alike, with the ConditionExpression or UpdateExpression
prefix. UpdateItem and a TransactWriteItems Update run it just ahead of
the path check, so the checks that already ran before it keep their
place. A #name in an update path is still refused by the earlier check
of each handler, as on main, except a name after the first step of a
path on TransactWriteItems, which now carries the UpdateExpression
prefix.

The update path check and the PartiQL overlap check share one
classifier, paths_meeting. Those two and the ProjectionExpression
overlap check share one message, paths_meet_message. The UpdateItem
envelope comes from validation_errors_detected. Two shapes the service
accepts join the tests: a name that holds a dot, and a path on the
right side of SET. The upgrade manual lists the change under v1.2.0.

Measured in us-east-1 on 2026-12-01, each request sent twice.

Signed-off-by: Elise Ong <eliseong@amazon.com>
@eliseong

eliseong commented Dec 4, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks. 6da1a96 adds the v1.2.0 entry to docs/manuals/07-upgrade-manual.md, and the description now lists the TransactWriteItems change under Breaking changes. The reply on line 265 covers the check order. The description now says what 23 and 25 count, lists the rows that still differ, and names #507 beside #399 in the merge plan.

@LeeroyHannigan LeeroyHannigan 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.

Thanks for the fixes and the replies. I built 6da1a96: cargo test -p extenddb-core -p extenddb-engine --lib passes 1263 and 981 tests, and clippy and fmt are clean. CI passes 76 checks. I sent the 1 December requests, 34 of them and each twice, to a dev-mode server built from this head. The five rows of my comment on line 265 and the SET a.#u = :b of the comment on line 581 now give the service's answer. No other row changed, and tests/test_update_expression_paths.py passes 15 of 15.

I sent 13 more requests to DynamoDB in us-east-1 today, each twice, with the table missing. Rows 3 to 8 of update_refs_name_the_first_undefined_reference get the names and values the test expects. SET #u = :b with the condition attribute_exists(#q), where neither name is defined, gets #q. GetItem with the ProjectionExpression a.b, a[0] gets the conflict text, as the description says. The other five requests are in the comment on line 417 of the upgrade manual.

Both conditions of the first round are met, and so are the smaller comments and the description points. One change is still needed. The new upgrade-manual entry says that 1.1.0 refused an undefined reference with another text, but 1.1.0 applied some of those requests. The comment on line 417 has the rows.

The comment on resolver.rs:397 is smaller. On the description, the list of rows that still differ from the service leaves out two TransactWriteItems rows of 1 December. With SET a.b = :b, a[0] = :z on a missing table, or with an empty key value, the service names the conflict. This branch answers ResourceNotFoundException or the empty key refusal, as main does. Please add them.

The merge plan still holds. #399, #507, #597 and #1140 are open and change the same functions.

#1093 merged at 08:59 UTC and adds a v1.2.0: entry at the top of the same section, so the upgrade manual now conflicts with main. Both entries can stay.

`ConditionExpression` first and then each action, its path and then its value.
The text starts with `Invalid ConditionExpression: ` or `Invalid
UpdateExpression: `, and on `UpdateItem` with `1 validation error detected: `.
1.1.0 answered these on `UpdateItem` without `1 validation error detected: `,

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.

1.1.0 read a reference only when it evaluated it, so it applied some requests that this release refuses. I sent these to main and to this head on an item {pk, y: 1, a: {b: 1}}, and to DynamoDB in us-east-1 today with the table missing, each twice:

Request DynamoDB main this head
UpdateItem SET x = if_not_exists(y, :q), :q not defined undefined value :q applied, x written as DynamoDB
UpdateItem SET x = :b, condition attribute_exists(pk) OR #q = :b, #q not defined undefined name #q, in the ConditionExpression applied as DynamoDB
UpdateItem SET x = :b, condition attribute_not_exists(pk) AND #q = :b undefined name #q, in the ConditionExpression ConditionalCheckFailedException as DynamoDB
TransactWriteItems Update, the first row's request undefined value :q applied as DynamoDB
TransactWriteItems Update, the second row's request undefined name #q, in the ConditionExpression applied as DynamoDB

So the refusal is right. This sentence says that 1.1.0 refused these with another text, though, and lines 425 to 428 say it answered them on TransactWriteItems with TransactionCanceledException. Please say that 1.1.0 applied such a request when it did not reach the reference, or answered ConditionalCheckFailedException. This release refuses it and writes nothing. Breaking changes needs the same point. Please also add the first two rows to the wire test.

}

/// The references of `expr` in expression order, left to right.
fn refs_in_order<'a>(expr: &'a super::ast::Expr, out: &mut Vec<Ref<'a>>) {

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.

refs_in_order walks the same expression arms as collect_expr_refs at line 498, and path_refs_in_order is collect_path_refs at line 594, with a list in place of two sets. first_undefined at line 473 also writes the two texts of ExpressionMaps::resolve_name and resolve_value_for again. Please keep one ordered walk that both callers use, and build the two refusals from those two functions. If a copy has to stay, please say why in the description.

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.b = :b, a[0] = :z answers the invalid-path text; the service refuses the two paths as conflicting

2 participants