Skip to content

fix(core): report the first ProjectionExpression fault in written order - #1140

Open
LeeroyHannigan wants to merge 6 commits into
fix/document-path-length-on-399from
fix/1024-projection-fault-order
Open

LeeroyHannigan wants to merge 6 commits into
fix/document-path-length-on-399from
fix/1024-projection-fault-order

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

  • a51c583 moves the #u.name row of test_first_fault_in_written_order to FIRST_FAULT_ALL_READS, so all five reads send it. It also adds the row a, a.name there. DynamoDB answered both rows on all five reads on 3 December.
  • 1bc6167 states in docs/dynamodb-limits.md that the service checks reserved words in the same walk for the other expression kinds too (measured on 3 December).
  • The What section now says that the enforce_reserved_keywords argument changes no answer in the two PartiQL projections.

What

ExtendDB now reports the first fault of a ProjectionExpression in written order, as DynamoDB does. It checks each path in turn. A path reports its first faulty element, and an overlap is a fault of the later path.

Before this change, ExtendDB checked every token for a reserved word before it read any path. So #u, name, a, a.b, name and #u.name got the reserved word name, where DynamoDB names the first fault. On origin/main, a.b, c.d, c, a also names the pair [a, b], [a], where DynamoDB names [c, d], [c]. #597 fixes that pair: it checks each path against the earlier paths in resolve_paths. This PR builds on #597 and adds these changes:

  • resolve_paths checks a bare name for a reserved word in its PathElement::Attribute arm, before it resolves the next element. So #u.name names #u, and name.#u names name.
  • Projection::compile takes a fourth argument, reject_reserved. Each read handler passes enforce_reserved_keywords. The two PartiQL projections give every name a placeholder: #n in the transaction read and #p in RETURNING. So the argument changes no answer there. The transaction read passes enforce_reserved_keywords, and RETURNING passes false. The UpdateExpression caller of resolve_paths passes false, so UpdateExpression paths keep their check on the token stream.
  • parse_projection_expr no longer checks the token stream for reserved words, so a syntax error comes first.
  • validate_not_reserved writes the reserved word text for both checks.
  • docs/dynamodb-limits.md now says that a ProjectionExpression checks its reserved words in the same walk as its paths, as the service does. For the other expression kinds, the row now says that the service checks them in the same walk too. ExtendDB keeps the check on the whole expression there.

Why

These are DynamoDB's answers, measured in us-east-1 on 14, 18 and 24 November and 3 December 2026. Each request went out twice and got the same answer both times. On each row, every read in the last column gave the same answer.

ProjectionExpression DynamoDB, after Invalid ProjectionExpression: Measured on
#u, name An expression attribute name used in the document path is not defined; attribute name: #u GetItem on 14 Nov, the other four reads on 18 Nov
a, a.b, name and a, a.b, #u Two document paths overlap with each other; must remove or rewrite one of these paths; path one: [a], path two: [a, b] GetItem on 14 Nov, the other four reads on 18 Nov
a.b, c.d, c, a the overlap text with path one: [c, d], path two: [c] GetItem on 14 Nov, the other four reads on 18 Nov
#u.name the undefined #u text GetItem and Query on 18 Nov, Scan and TransactGetItems on 24 Nov, all five reads on 3 Dec
name.#u Attribute name is a reserved keyword; reserved keyword: name GetItem and Query on 18 Nov, Scan, BatchGetItem, TransactGetItems and SearchVectors on 24 Nov
a, a.name the reserved word text all five reads on 3 Dec
name, #u and a, name, a.b the reserved word text GetItem on 18 Nov
name, a..b, a..b, name and a[name] Syntax error; token: ... GetItem on 18 Nov, and a..b, name on TransactGetItems on 24 Nov
a path of 33 elements, then the path name the 33-level path length text of #597 GetItem on 18 Nov
the path name, then a path of 33 elements the reserved word text GetItem on 18 Nov
a path of 33 elements with .name after them the reserved word text GetItem on 18 Nov

Closes #1024

Not in this PR

Each of these is in an issue:

Conflicts

This PR adds no conflict with any open PR. 58 open PRs change its files, and each of them conflicts with this head in the same files as with #597's head (git merge-tree, 3 December). #1543 changes resolve_paths, to which this PR adds an argument, and it already conflicts with #597 in projection.rs.

Against main at c057660361, this head and #597's head conflict in the same 12 files. Against #399's head edb464c7da, which merged that main, both conflict in evaluator.rs, evaluator_tests.rs and expression_helpers.rs.

Testing done

All runs are on 1bc616769a, except where a line names e1a5f1bfd. The two commits have the same Rust code, and both servers are builds of e1a5f1bfd.

  • cargo test -p extenddb-core --lib: 1157 passed, 1 ignored.
  • cargo test -p extenddb-engine --lib: 878 passed.
  • These commands are clean: cargo clippy --all-targets --features extenddb-storage-cassandra/test-hooks,extenddb-storage-mongodb/test-hooks -- -D warnings, cargo clippy --all-targets --features extenddb-engine/backup-test-hooks -- -D warnings, cargo fmt --all -- --check and cargo +1.94.0 check -p extenddb-core -p extenddb-engine --all-targets. With -W clippy::pedantic on the two crates, no warning is on a line that this PR adds.
  • Against ExtendDB on SQLite and on PostgreSQL, ten wire files passed 505 tests each: tests/test_projection_overlapping_paths.py, tests/test_nested_projection.py, tests/test_expression_error_prefix.py, tests/test_validation_precedence.py, tests/test_document_path_length.py, tests/test_item_operations.py, tests/test_query_scan.py, tests/test_transact_expression_validation.py, tests/test_transact_update_remove_only.py and tests/test_transact_validation_order.py. The new test test_first_fault_in_written_order sends 7 rows to all five reads and 2 more expressions to GetItem.
  • the_vector_attribute_is_returned_only_when_named in tests/rust passed with EXTENDDB_EXPECT_VECTORS=1.
  • With the token stream check of fix(core): refuse a document path of more than 32 elements #597 put back in a server, test_first_fault_in_written_order fails 15 of its 37 cases: #u, name, a, a.b, name and #u.name on all five reads.
  • The engine test projection_reports_the_first_fault_in_written_order holds every row above except a, a.name. At e1a5f1bfd, with the token stream check of fix(core): refuse a document path of more than 32 elements #597 put back, it fails on its first row. With the same check and the three rows of 33 elements first, it fails on the path of 33 elements and then name.
  • At e1a5f1bfd, with false passed at the Scan, BatchGetItem, TransactGetItems and SearchVectors callers, the name.#u cases of Scan, BatchGetItem and TransactGetItems fail. The SearchVectors test fails too.
  • python3 -m pytest --collect-only collects tests/ (7032 tests) and tests/python (672 tests) with no error.

Line counts against #597: production +59 -22, tests +155 -6, docs +1 -1. The #[cfg(test)] helper apply_projection counts as tests.

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

A ProjectionExpression with more than one fault now answers the fault that DynamoDB answers: a syntax error first, then the first fault in written order. Before, a reserved word anywhere in the expression answered first. The status 400 and the error code ValidationException do not change.


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.

Amazon DynamoDB checks the paths of a ProjectionExpression in written
order. A path reports its first faulty element, and an overlap is a
fault of the later path. ExtendDB checked every token for a reserved
word before it read any path. So it named the reserved word for
"#u, name", "a, a.b, name", "#u.name" and "name, a..b".

The reserved word check now runs where Projection::compile resolves
each path, element by element. A bare name is checked before the next
element is resolved. So "#u.name" names #u, and "name.#u" still names
the reserved word. A syntax error now comes before the check. The
callers pass enforce_reserved_keywords to Projection::compile.
UpdateExpression paths keep their check on the token stream.

DynamoDB gave these answers on GetItem on 2026-11-14, and on GetItem,
Query, Scan, BatchGetItem and TransactGetItems on 2026-11-18.

Fixes #1024.
Each read handler and the PartiQL transaction read pass
enforce_reserved_keywords. The PartiQL RETURNING projection passes false,
because all its names are placeholders. No test sent Scan, BatchGetItem
or SearchVectors a projection that DynamoDB answers with the reserved
word. So no test failed when one of those handlers passed false.

The name.#u row now goes to GetItem, Query, Scan, BatchGetItem and
TransactGetItems. The vector projection test sends it to SearchVectors.
DynamoDB answered the reserved word for it on GetItem and Query on
2026-11-18, and on Scan, BatchGetItem, TransactGetItems and SearchVectors
on 2026-11-24.

_validation_message now also checks the HTTP status 400.

The module docstring no longer names the AWS CLI as the source of the
messages.
…exts

The engine table now holds the three rows with a path of 33 elements.
For a path of 33 elements and then the path name, ExtendDB now answers
the path length text. The token check of the base answered the reserved
word. The path name and then a path of 33 elements, and a path of 33
elements with .name after them, answer the reserved word. DynamoDB gave
these answers on GetItem on 2026-11-18.

The syntax rows now compare ExtendDB's own parser text by equality. So an
undefined name or an overlap answer fails them. The service words a
syntax error differently (#839). The doc comment of the test lists the
reads that went to DynamoDB for each row.
docs/dynamodb-limits.md said that ExtendDB checks reserved words on the
whole expression before any path, for every expression kind. That is no
longer true for a ProjectionExpression: it checks them in the same walk
as its paths, as the service does. The other kinds keep the check on the
whole expression.

In the doc comments, resolve_paths now names its reject_reserved check,
and Projection::compile writes DynamoDB in backticks, as the clippy
doc_markdown lint asks.

@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 ran #u.name against all five reads on this branch and on #597. This branch answers the undefined #u on all five, and #597 answers the reserved word on all five. The test pins it only for GetItem (FIRST_FAULT_GET_ITEM), while the description says it was measured on GetItem, Query, Scan and TransactGetItems. Could you move it to FIRST_FAULT_ALL_READS, or add the three measured reads? BatchGetItem is not in the measured list for this row, so I think it needs a measurement or should be left out.

In docs/dynamodb-limits.md, the old text said the service checks reserved words in the same walk as the paths. The new text says ExtendDB checks them on the whole expression for the other kinds, but no longer says what the service does for those kinds. Was the service's order for, say, a ConditionExpression measured? If it was, I think the clause should stay so the row still shows the difference. If not, could the row say it was not measured?

member_projection in partiql/transaction.rs renders every path through ExprBridge::path, which gives each name a #n placeholder, so the bare name check never fires there. That is the same reason RETURNING passes false. Passing enforce_reserved_keywords is harmless, but the description reads as if it changes something. Could you pass false with the RETURNING comment, or reword that line?

A question on a shape the table does not cover: when a later path both overlaps an earlier one and holds a reserved word, as in a, a.name, this branch answers the reserved word, because the check runs on each element before the overlap check. Has anyone measured what DynamoDB answers for that?

A note on the base: git merge-tree of this head with current main conflicts in 11 files. The same 11 conflict for #597's head, and #399 shows DIRTY, so this comes from main moving under #399 and #597, not from these commits. The green CI ran on the merge with the #597 branch.

I will approve once #u.name is pinned on the measured reads and the doc row says what the service does for the other kinds.

The #u.name row was in FIRST_FAULT_GET_ITEM, so only GetItem sent it.
On 3 December 2026 DynamoDB answered the undefined #u text for #u.name
on GetItem, Query, Scan, BatchGetItem and TransactGetItems. The row now
sits in FIRST_FAULT_ALL_READS.

In a, a.name the later path overlaps the earlier one and holds a
reserved word. The five reads answered the reserved word text on the
same day, and ExtendDB gives the same answer. That row goes into
FIRST_FAULT_ALL_READS too.

Each request went to a table name that does not exist, twice, with the
same answer both times.
The document path length row said what ExtendDB does for the other
expression kinds, but not what the service does. On 3 December 2026 the
service got a path of 33 elements followed by name in four kinds:
ConditionExpression, FilterExpression, KeyConditionExpression and
UpdateExpression. It answered the length error for all four, and
ExtendDB answers the reserved word error. The row now states both
orders.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol

  1. #u.name is now in FIRST_FAULT_ALL_READS (a51c583), so all five reads send it. I measured BatchGetItem as well. On 3 December, GetItem, Query, Scan, BatchGetItem and TransactGetItems each answered Invalid ProjectionExpression: An expression attribute name used in the document path is not defined; attribute name: #u, twice each, on a table name that does not exist. With fix(core): refuse a document path of more than 32 elements #597's token check put back, the row fails on all five reads. Before a51c583, only its GetItem case ran.

  2. Yes, measured on 3 December, on the same missing table. A path of 33 elements followed by name got the length error in all four other kinds: ConditionExpression (PutItem), FilterExpression (Scan), KeyConditionExpression (Query) and UpdateExpression (UpdateItem). For example, the ConditionExpression attribute_exists(<33 elements>) AND attribute_exists(name) answered 1 validation error detected: Invalid ConditionExpression: The document path has too many nesting levels; nesting levels: 33. Your shape, attribute_exists(#u) AND attribute_exists(name), answered the undefined #u. This branch answers the reserved word in all five requests. 1bc6167 restores the service's order in the row. It now reads: "For the other expression kinds, the service checks reserved words in the same walk too (measured 2026-12-03). ExtendDB checks them on the whole expression before any path." PutItem ConditionExpression: ExtendDB reports a reserved word ahead of an undefined #name, an undefined :value or a wrong operand type written before it #1031 and Query reports OR and a reserved word in a KeyConditionExpression ahead of an undefined value #1007 track this order for ConditionExpression and KeyConditionExpression, and FilterExpression, ConditionExpression, KeyConditionExpression and UpdateExpression: ExtendDB reports a reserved word ahead of a long path written before it #1567 has the four long path rows.

  3. I changed the description and kept the code. As you say, ExprBridge::path gives every name in member_projection a #n placeholder, so the check has nothing to refuse there, and true and false give the same answer. The description now says that the read handlers pass enforce_reserved_keywords, and that the argument changes no answer in the two PartiQL projections.

  4. Measured on 3 December on all five reads: a, a.name answers Invalid ProjectionExpression: Attribute name is a reserved keyword; reserved keyword: name, twice each. The reserved word of the later path comes before its overlap, as #u does in a, a.#u. This branch gives the same answer. fix(core): refuse a document path of more than 32 elements #597's token check gives it too, so the PR does not change this answer. The row is now in FIRST_FAULT_ALL_READS too.

  5. fix(expressions): validate in the service's order, with its messages #399's branch merged main c057660361 on 3 December (1fbf0657c5), and its head is now edb464c7da. Against main, this head and fix(core): refuse a document path of more than 32 elements #597's head both conflict in the same 12 files today. Against fix(expressions): validate in the service's order, with its messages #399's new head, both conflict in the same 3 files: evaluator.rs, evaluator_tests.rs and expression_helpers.rs. fix(core): refuse a document path of more than 32 elements #597 has an approval, so its update with fix(expressions): validate in the service's order, with its messages #399's head is a separate step. This PR then merges fix(core): refuse a document path of more than 32 elements #597's new head.

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

@LeeroyHannigan points 1, 2, 3 and 5 are resolved at 1bc6167, and point 4 is answered for a, a.name.

  1. #u.name is in FIRST_FAULT_ALL_READS now, so all five reads send it. On a SQLite server, the ten wire files from your description pass on this head (557 passed with my extra cases, 505 without them). On #597's head (7029242) the same files fail in test_first_fault_in_written_order for #u, name, #u.name and a, a.b, name on all five reads. That is the 15 of 37 cases you give. The a, a.name rows pass on #597 too, so they guard the answer and do not detect this change. Your BatchGetItem measurement of 3 December is yours and I did not repeat it.

  2. The doc row now says the service checks reserved words in the same walk for the other kinds and that ExtendDB checks the whole expression first. I checked the ExtendDB half on this head: a 33 element path followed by attribute_exists(name) answers the reserved word in a ConditionExpression and a FilterExpression, and the same in an UpdateExpression with SET <33 elements> = :v, name = :v. #597 gives the same answers, so the row describes behaviour that was already there. I did not send a reserved word after a long path in a KeyConditionExpression. The service half of the sentence is your measurement.

  3. I read the description. It now says the argument changes no answer in the two PartiQL projections, and the code did not change, so the text matches the code. SELECT "name", "size" through ExecuteStatement and ExecuteTransaction gives the same answer on this head and on #597.

  4. a, a.name answers the reserved word on all five reads on this head, and on #597 as well, so this PR does not change it. The service answer is your measurement. For l[0], l[0].name I also get the reserved word on this head and on #597. Your reply names only a, a.name. Is the service answer for l[0], l[0].name the same? I do not ask for a change.

  5. I get the same conflict lists as you. Against main at db8a90d, this head and #597's head conflict in the same 12 files, among them update_parser.rs (deleted here, modified on main). Against #399's head edb464c both conflict in evaluator.rs, evaluator_tests.rs and expression_helpers.rs.

I ran SQLite only here. The service statements in the description and in your reply are your measurements.

Points 1, 2, 3 and 5 are resolved and point 4 is answered, so I approve. The merge to main waits for #399 and #597 to be updated with main.

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.

2 participants