Skip to content

fix(core): refuse a name that starts with an underscore in an expression - #1131

Open
LeeroyHannigan wants to merge 24 commits into
mainfrom
fix/1018-underscore-name
Open

LeeroyHannigan wants to merge 24 commits into
mainfrom
fix/1018-underscore-name

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

LJMart11 reviewed 69e81e3 on 4 December. One commit comes after that review:

navareamol reviewed 9e475b4. These commits came between that review and the review of 69e81e3:

  • a6bf351 checks the size of the filter and of the projection of a Query ahead of a missing table, as DynamoDB does. Why has the measurements of 4 December 2026. When the table lookup fails, handle_query now checks the filter, then the key condition, then the projection. Each one gets the size check and then the tokenizer. The filter's size error there has no expression size suffix, as on DynamoDB. The engine test of a missing table gets four rows. tests/test_expression_leading_underscore.py gets the two size rows and a row with _g = :v and the projection _x.
  • dd08869 merges main at 5826e1b, four PRs after the last merge. One file conflicted. In docs/manuals/07-upgrade-manual.md, fix(storage-sqlite): keep each partition key in one parallel Scan segment #1087 added its v1.2.0 entry where this PR has its entry. The merge keeps the entries of main first.
  • ca7645b allows clippy::too_many_lines on the missing-table test. The four new rows take its data table to 113 lines, and the pedantic lint warns over 100. The function holds one row per measured request.
  • 69e81e3 corrects the doc of check_expression_size in crates/core/src/expression/kind.rs. It still named Filter and Condition as the kinds whose size error carries the byte length. Since a6bf351, only Condition does.
  • In this description: What, Why, Not in this PR, Other open PRs, Testing done and Breaking changes.

Please use the PR title and the What section as the squash message when this PR merges. GitHub's commit list of this PR holds the eight commits of #567, which main already has as the squash 97729ce.

What

ExtendDB now refuses an attribute name that starts with _ when an expression writes it without a #name placeholder, as Amazon DynamoDB does. Every expression member answers Invalid <member>: Syntax error; token: "_", near: "<text>". Before this change ExtendDB read _x as a name and served the request.

is_ident_start in the tokenizer now accepts only a letter. A _ at the start of a name reaches the tokenizer's arm for a character outside the grammar. #567 gives that arm DynamoDB's window, from the start of the previous token to the end of the next one. An underscore after the first character, in a #name and in a :value is still part of the name.

PutItem, UpdateItem and DeleteItem put 1 validation error detected: ahead of this refusal. The other operations, TransactWriteItems included, send it alone. count_leading_underscore_refusal adds the count where the single-item writes parse: in resolve_condition and in the UpdateExpression parse of UpdateItem.

A Query of a table that does not exist now checks its expressions before it reports the missing table. It checks them in DynamoDB's order: the filter, then the key condition, then the projection. On each one, it runs the size check and then the tokenizer. These are the first two steps of the parse of each member on a table that exists. A member over 4096 bytes gets the size error. An expression that the tokenizer refuses gets the tokenizer's answer. That covers a _ at the start of a name, a character outside the grammar, a bare # or : and an empty expression.

The filter's size error on a missing table has no expression size: <n> suffix, as on DynamoDB. handle_query checks it as ExpressionKind::Filter, so size_error_includes_length no longer includes Filter. No other code checks a size as Filter. On a table that exists, the filter parse checks the size as Condition, and ExtendDB keeps the suffix there. DynamoDB left the suffix out of the errors that #1421 measured, and #1421 tracks the difference.

With this order, pk = é gets DynamoDB's answer, Syntax error; token: "é", near: "= é". A bare # gets near: "#", where DynamoDB answers near: "= #" (#1419). The other faults keep the missing-table answer.

The same is_ident_start change answers a comment on #567 about the window after a leading _. #v = é _abc and #v = é __x now get near: "= é _".

count_leading_underscore_refusal is a second copy of a count that two open PRs add in the same two places: #1095 (count_list_index_refusal) and #399 (single_item_write_prefix). Both of them count every syntax error of the single-item writes. This PR keeps its own copy, because it can merge before them. When one of them merges, this PR drops its copy.

#567 merged into main on 25 November as 97729ce, and its branch fix/tokenizer-multibyte is gone. This PR targets main.

Why

These are DynamoDB's answers, measured in us-east-1. The rows of the issue date from 14 November 2026. On 18 November 2026, more requests went to DynamoDB, and each one went out twice with the same answer both times:

  • A TransactWriteItems Put, Delete or ConditionCheck with attribute_exists(_x) gets the syntax error with no count. An UpdateItem ConditionExpression gets the count.
  • a[1_] gets near: "1_]" in a ProjectionExpression and in a ConditionExpression.
  • On a table that does not exist, a Query with the key condition _g = :v gets the syntax error, and an empty key condition gets Invalid KeyConditionExpression: The expression can not be empty;. The key condition size = :v gets ResourceNotFoundException.
  • DynamoDB serves a_b, #_x and :_v in every expression of every operation, and the PartiQL statements keep their answers.
  • A Scan filter #v = é _abc or #v = é __x gets near: "= é _".

On 25 November 2026, more Query requests went to a table that does not exist, each one twice with the same answer both times:

  • Three key conditions over 4096 bytes each get Invalid KeyConditionExpression: Expression size has exceeded the maximum allowed size;:
    • 4100 (, then pk = :v, then 4100 ). This key condition is over the token limit too.
    • pk = :v, then 4100 spaces.
    • A name of 4100 bytes, then = :v.
  • pk = é gets Invalid KeyConditionExpression: Syntax error; token: "é", near: "= é", and pk = # gets Invalid KeyConditionExpression: Syntax error; token: "#", near: "= #".

On 3 December 2026, these Query requests went to a table that does not exist, each one twice with the same answer both times. Each one has ExpressionAttributeValues {":v": {"S": "x"}}:

Key condition Filter Projection DynamoDB
pk = :v _x = :v Invalid FilterExpression: Syntax error; token: "_", near: "_x"
pk = :v _x Invalid ProjectionExpression: Syntax error; token: "_", near: "_x"
pk = :v a = @ Invalid FilterExpression: Syntax error; token: "@", near: "= @"
pk = :v the empty string Invalid FilterExpression: The expression can not be empty;
_g = :v _x = :v the filter's syntax error
_g = :v _x Invalid KeyConditionExpression: Syntax error; token: "_", near: "_g"
pk = :v _x = :v _y the filter's syntax error
pk = :v and 4100 spaces _x = :v the filter's syntax error

A Scan with the filter _x = :v on a table that does not exist gets Invalid FilterExpression: Syntax error; token: "_", near: "_x" too.

On 4 December 2026, these Query requests went to a table that does not exist, each one twice with the same answer both times. They have the same ExpressionAttributeValues. "+ 4100 spaces" means the text and then 4100 spaces, over the limit of 4096 bytes:

Key condition Filter Projection DynamoDB
pk = :v a = :v + 4100 spaces Invalid FilterExpression: Expression size has exceeded the maximum allowed size;
pk = :v a + 4100 spaces Invalid ProjectionExpression: Expression size has exceeded the maximum allowed size;
pk = :v _x = :v + 4100 spaces the filter's size error
pk = :v _x + 4100 spaces the projection's size error
_g = :v a = :v + 4100 spaces the filter's size error
_g = :v a + 4100 spaces Invalid KeyConditionExpression: Syntax error; token: "_", near: "_g"
pk = :v + 4100 spaces a + 4100 spaces Invalid KeyConditionExpression: Expression size has exceeded the maximum allowed size;
pk = :v a = :v + 4100 spaces _x the filter's size error
pk = :v a and 4096 z, then = :v the filter's size error
_g = :v _x Invalid KeyConditionExpression: Syntax error; token: "_", near: "_g"

DynamoDB also sent the filter's size error with no suffix to a Scan of a table that does not exist. Its filter was a = :v + 4100 spaces, or the 4102-byte filter of the long name.

Closes #1018

Not in this PR

Other open PRs

Testing done

The runs below are on ca7645b. The wasm-adapter tests, the docs test, the WebAssembly clippy step and the PostgreSQL wire run are on dd08869. ca7645b adds only the lint attribute to a test. 69e81e3 changes one line of a doc comment, and cargo +1.97.0 fmt --all -- --check is clean on it. a6bdace changes five lines of a doc comment. On it, cargo +1.97.0 fmt --all -- --check is clean, and cargo +1.97.0 clippy -p extenddb-core --all-targets -- -W clippy::pedantic gives no warning in kind.rs.

  • cargo test -p extenddb-core --lib: 1260 passed, 1 ignored.
  • cargo test -p extenddb-engine --lib: 984 passed.
  • cargo test -p extenddb-wasm-adapter, its parity corpus test included: 4 passed.
  • cargo +1.97.0 fmt --all -- --check is clean. Both clippy commands of .github/workflows/clippy.yml with -D warnings are clean on extenddb-core and extenddb-engine, and so is cargo +1.94.0 check --all-targets on the same crates.
  • cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine --all-targets -- -W clippy::pedantic gives no warning on a line that this PR adds.
  • The clippy step of .github/workflows/wasm.yml is clean.
  • cargo test -p extenddb-storage-postgres --test doc_version_literals: passed.
  • tests/test_expression_leading_underscore.py, tests/test_expression_unknown_character.py and tests/test_expression_size_limit.py give 110 passed and 9 expected failures against a SQLite server, and the same against a PostgreSQL server. The 9 are the rows of fix(expression): report a character outside the grammar without closing the connection #567 for the count that ExtendDB leaves out. The three new rows pass.
  • --collect-only collects 7390 tests in tests/ and 820 in tests/python, with no error.
  • Controls, with the new tests:
    • With query.rs of 9e475b4, the engine test fails at its first size row, which gets the filter's syntax error. On a SQLite server, the two size rows of tests/test_expression_leading_underscore.py fail, and the other 47 tests of the file pass.
    • With kind.rs of 9e475b4, the engine test fails at the same row, whose answer ends in ; expression size: 4107.
  • On a SQLite server, the Query requests of the 4 December table get DynamoDB's answers on a table that does not exist. The two Scan requests get the size error with the suffix (The expression size error on FilterExpression and ConditionExpression appends the byte length, which DynamoDB leaves out #1421).

Line counts over main: production +77 -16, tests +493 -12, and 6 added lines of the upgrade manual. Production is the Rust code outside test modules. Counted the same way at 9e475b4, they were production +67 -9 and tests +448 -12. a6bdace replaces five doc lines that this PR adds, so the counts do not change with it. The last description gave production +73 -9 by another count.

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 expression that writes an attribute name that starts with _ without a #name placeholder now gets ValidationException, as on DynamoDB, where main served it. A request can still use such a name through ExpressionAttributeNames.

On a table that does not exist, a Query now gets ValidationException when its key condition, its filter or its projection is over 4096 bytes. It also gets it when the tokenizer refuses its filter, its key condition or its projection. Main answered ResourceNotFoundException.


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.

LeeroyHannigan and others added 9 commits October 25, 2026 17:33
…e does, without a panic

The tokenizer behind condition and filter expressions read the offending
byte as a char and sliced the input five bytes either side of it. When that
range ended inside a multi-byte character (`#v = ééé`, `#v = 日本語`) the
slice panicked, the request task ended and the connection closed; the
server's key condition parse ahead of authorization calls the same tokenizer,
so a Query key condition did the same for every principal. Other multi-byte
input answered a token made of the first byte read as Latin-1. The tokenizer
behind update, projection and the engine's key condition parse did not panic
and answered the character with one byte after it as the window.

The error now names the character as sent and shows the service's window:
the source text from the start of the previous token to the end of the next
one, with each character outside the grammar counted as one token (measured
2026-10-25, each request twice: `#v = ééé` answers `token: "é", near: "= éé"`,
`abéc = :v` answers `near: "abéc"`, `#v = $x` answers `near: "= $x"`). Both
tokenizer entry points share the rule.
Pure move, using the #[path] pattern evaluator_tests.rs uses; tokenizer.rs
had grown past 600 lines with the previous commit.
…rammar

Every row is a request measured against the service on 2026-10-25, each sent
twice: Scan filters with multi-byte and ASCII characters outside the grammar
in each position, and one or two rows each for PutItem conditions, Query key
conditions, UpdateItem update expressions and GetItem projections.
…drop U+0000, as the service does

When no token comes before the character, the service starts the window at
the start of the expression and keeps the leading whitespace (`  é = :v`
answers `near: "  é ="`), and it removes U+0000 from the token and the
window (`#v = \0x` answers `token: "", near: "= x"`). Measured 2026-10-25 at
16:34, 16:38 and 16:43 UTC, each request twice. The unit table gains those
rows and the rows that pin the next-token rules for two-character operators,
name runs and digit runs.
…ken rules and the Query paths

Rows measured on 2026-10-25 at 16:34, 16:38, 16:43 and 16:54 UTC, each
request twice: a character with no token before it, U+0000, two-character
operators, name runs and digit runs after the character, and the panic shape
on a Query key condition, a Query filter and an UpdateItem condition. The
prefix the service adds on write paths is stripped only on those paths.
crates/core/src/expression/tokenizer.rs: main fixed the panic in
tokenize_with_limit by moving both ends of the five-byte window out to
character boundaries and reporting the whole character as the token.
This branch answers the window the service answers, measured on
2026-10-25: from the start of the previous token to the end of the next
one, from the start of the expression when no token comes before the
character, with U+0000 removed. The result keeps this branch's
unknown_character and next_token_end, which slice on character
boundaries and so cover the panic main fixed. main's five-byte window
code is superseded. The tests stay in tokenizer_tests.rs, where this
branch moved them.

main's three new tests move from tokenizer.rs into tokenizer_tests.rs.
tokenize_multibyte_utf8_near_an_invalid_byte_does_not_panic stays as
main wrote it; its one window assertion, "$  日" for the input "$  日",
matches the measured rule. tokenize_reports_the_whole_invalid_character
keeps its token assertion, and its window for "a = é" changes from
"a = é" to "= é", the window the measured row for "#v = é" gives.
tokenize_ascii_error_context_is_five_bytes_either_side is dropped: it
asserted the window "s(a) $ b" for "attribute_exists(a) $ b", five
bytes either side of the character, and the measured rule answers
") $ b" for that input.
New rows in the tokenizer table cover a tab, a line feed and a carriage
return before the next token. The doc of next_token_end says that a
bare # or : counts as a one-byte token, as DynamoDB counts it.

One window check now compares the whole message with assert_eq. The
table check of tokenize_for uses the Update kind, which production
passes. Two test comments now describe the window the tokenizer builds.

The wire tests compare the whole PutItem, UpdateItem and DeleteItem
message, which starts with the count "1 validation error detected: ".
Those rows are an expected failure on ExtendDB, which leaves the count
out.

New wire rows cover a DeleteItem condition and the four
TransactWriteItems kinds. More rows cover a projection on Query, Scan,
BatchGetItem and TransactGetItems, and a key condition on a global
secondary index. They share one data table and one parametrized test.

Each new row expects the text DynamoDB returned on 2026-11-18 in
us-east-1. Each request went out twice and got the same answer both
times.
Amazon DynamoDB refuses an attribute name that starts with `_` when an
expression writes it without a `#name` placeholder. Every expression
member answers with a syntax error at the `_`. Its near text runs from
the token before the `_` to the token after it. ExtendDB read `_x` as a
name and served the request.

A name now starts with a letter. The tokenizers refuse a `_` at the
start of a name with the syntax error they write for other characters.
An underscore after the first character, in a `#name` and in a `:value`
is still part of the name.

PutItem, UpdateItem and DeleteItem put `1 validation error detected: `
ahead of this refusal. Query, Scan, GetItem, BatchGetItem,
TransactGetItems and TransactWriteItems send the syntax error alone.

DynamoDB reads the key condition before it looks up the table. When a
Query names a table that does not exist, ExtendDB now tokenizes the key
condition before it reports the missing table. It refuses a `_` and an
empty key condition there as DynamoDB does.

Measured in us-east-1 on 2026-11-14 and 2026-11-18, each request twice.

Fixes #1018.
The comment on the missing-table Query test said that Amazon DynamoDB
does not check reserved words ahead of the table lookup. On a table
that does not exist, DynamoDB refuses `status = :v` as a reserved word
(measured 2026-11-19). The `size = :v` row gets
ResourceNotFoundException because the service reads `size` as a name.
The comment now states both facts.
@LeeroyHannigan
LeeroyHannigan marked this pull request as ready for review November 23, 2026 11:26
Base automatically changed from fix/tokenizer-multibyte to main November 25, 2026 10:57
Main is at 80490c6, 34 commits after the last merge. #567 is one of
them, squashed into 97729ce, and this branch starts from the branch
of #567. Three files conflicted, because this branch holds the commits
of #567 and main holds the squash.

For each file the merge takes the file of main and applies the change
of this branch from 637e7a9 and 5569436 on top:

- crates/core/src/expression/tokenizer.rs: is_ident_start accepts only
  a letter, with its doc comment.
- crates/core/src/expression/tokenizer_tests.rs: the test of a name
  that starts with "_" replaces tokenize_underscore_ident. The two rows
  of a "_" after an unknown character go after the "\r" row of
  UNKNOWN_CHARACTER_ROWS, where this branch put them.
- tests/test_expression_unknown_character.py: the file of main, which
  the commits of this branch do not change.

Git merged two other files that both sides change, with no overlap:
crates/engine/src/partiql/mod.rs and crates/engine/src/query.rs.
On a table that does not exist, Query tokenized the key condition but
did not check its size first. A key condition of more than 4096 tokens
got the token limit error. A key condition of more than 4096 bytes that
the tokenizer accepts got ResourceNotFoundException. On a table that
exists, parse_key_condition_expr runs the size check before the
tokenizer.

The missing-table branch now runs the same size check ahead of the
tokenizer. On a table that does not exist, Amazon DynamoDB answers
`Invalid KeyConditionExpression: Expression size has exceeded the
maximum allowed size;`. It gives that answer to three key conditions of
more than 4096 bytes. They are a key condition of 8203 tokens, `pk = :v`
with 4100 spaces after it, and a 4100-byte name with ` = :v`. Each
request went out twice, in us-east-1 on 2026-11-25. The Query test of a
missing table has a row for each of them.
The wire test of a name that starts with `_` gets the rows below. Each
expected answer is the answer of Amazon DynamoDB in us-east-1 on
2026-11-18, where each request went out twice.

- A TransactWriteItems Put, Delete and ConditionCheck with
  `attribute_exists(_x)` get the syntax error with no count.
- An UpdateItem `ConditionExpression` `attribute_exists(_x)` gets the
  count.
- `a[1_]` gets `near: "1_]"` in a Query ProjectionExpression and in a
  PutItem ConditionExpression.
- DynamoDB serves the PartiQL statements `SELECT _x, a._b` and
  `UPDATE ... SET _y = 1`. The module fixture writes the item that the
  UPDATE changes.

The count depends on the call site, so the transaction rows fail if a
transaction path starts to count the refusal. The test of a valid key
condition on a table that does not exist now compares the message as
well as the error code.
… name

The engine unit test of a name that starts with `_` had an UpdateItem
row that applied count_leading_underscore_refusal itself. Its
TransactWriteItems row checked the output of parse_update_expr, which
the fix does not change. A mutant that deletes the count from
update_item.rs passes every engine unit test and fails the UpdateItem
rows of the wire test. The unit test now keeps only the filter and
PutItem condition rows.

The tokenizer test loses a row that repeated the `_pk = :v` row of the
key condition. The doc comment of count_leading_underscore_refusal now
says that it counts a syntax error at a `_`. That covers `a[1_]` too.

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

Findings below. This head does not build once main is merged, and the branch conflicts with main.

  1. crates/engine/src/query.rs:23 imports check_expression_size from crate::expression_helpers. Since main moved that function into extenddb_core::expression, expression_helpers.rs only imports it privately. I merged this head into main 222d80a locally and got E0603: function import 'check_expression_size' is private, so cargo test -p extenddb-engine --lib does not compile. I think the fix is to import it from extenddb_core::expression in query.rs and drop it from the crate::expression_helpers list. With only that change on the merged tree, core lib passes (1241), engine lib passes (981), and the wire files test_expression_leading_underscore.py and test_expression_unknown_character.py give the same results as on this head (9 expected failures, none new).

  2. GitHub reports a conflict with main. It is one file, crates/engine/src/partiql/test_context.rs: main rewrote context() to build the context through crate::test_context::context_on, and this PR changes the visibility of the old body. I think taking main's file and changing pub(super) async fn context to pub(crate) async fn context is enough. The line in the description that says git merges the test_context change without a conflict is out of date after the merge.

  3. The red wasm check on this head fails in "Build the adapter for wasm32" with E0308 mismatched types. #1482 fixed that on main on 25 November and wasm.yml has been green on main since. I think merging main clears it. The other checks ran before the 18 commits that main has gained, so they need a new run on the merged branch. The description line about applying the two commits of #1482 can go.

  4. On a table that does not exist, Query with KeyConditionExpression: "pk = :v" and FilterExpression: "_x = :v" answers ResourceNotFoundException, and so does the same request with ProjectionExpression: "_x". Scan on a missing table with the same filter answers the syntax error, and Query on an existing table answers the syntax error. The upgrade manual says the refusal holds in the filter and projection expressions, and the docstring of tests/test_expression_leading_underscore.py says a filter is checked before the table lookup. Has anyone measured on the real service what Query answers for a valid key condition plus a _ filter on a missing table? If it answers the syntax error, I think the missing-table branch needs to scan the filter and projection too. If it answers ResourceNotFoundException, I think the manual and the docstring should say that Query's filter and projection are not checked first.

The rest I checked and it holds on this head. I ran the PR's wire file on this head and on a build of main: 31 refusal rows fail on main and pass here, so that file detects the change. I reverted the fix, the size check, the key condition scan and each of the two counts, and a test fails for each of the first four. Removing the count in the UpdateItem update-expression parse leaves every engine unit test passing and fails 4 wire rows (update-set, update-nested, update-remove, update-missing-table), as the description says. Tables whose key and index attributes start with _, the legacy parameters (Expected, AttributeUpdates, KeyConditions, QueryFilter, ScanFilter, AttributesToGet) and PartiQL statements on those tables are still served.

I will approve once the import is fixed, main is merged with a green CI run, and finding 4 is answered or the text is changed to match the code.

Main is at c8e66fb. This branch last had main at 80490c6. Since
then, 34 PRs merged into main, #1482 among them, which fixes the
WebAssembly build.

Two files conflicted:

- crates/engine/src/partiql/test_context.rs: main builds context()
  through crate::test_context::context_on (#1449), and this branch
  makes the old function pub(crate) for the missing-table test of
  query.rs. The merge takes the file of main and makes context
  pub(crate).
- docs/manuals/07-upgrade-manual.md: main added two v1.2.0 entries at
  the top of Behavior Changes by Release, where this branch added its
  v1.1.0 entry. The merge keeps the entries of main first, then the
  entry of this branch.

#1449 moved check_expression_size from
crates/engine/src/expression_helpers.rs to extenddb_core::expression,
where crates/engine/src/expression_helpers.rs imports it privately. So
crates/engine/src/query.rs now imports it from extenddb_core::expression.
Without that change the engine does not build (E0603). Git merged
expression_helpers.rs, partiql/mod.rs and query.rs with no other
conflict.
… table

On a table that does not exist, Query answered ResourceNotFoundException
to a filter or a projection that names `_x`. DynamoDB answers the syntax
error. Measured in us-east-1 on 3 Dec 2026, each request twice, with the
key condition `pk = :v`:

- FilterExpression `_x = :v`: `Invalid FilterExpression: Syntax error;
  token: "_", near: "_x"`
- ProjectionExpression `_x`: `Invalid ProjectionExpression: Syntax error;
  token: "_", near: "_x"`
- FilterExpression `a = @` and an empty FilterExpression get the
  tokenizer's other errors there too.

With faults in two of them, the service answers the filter ahead of the
key condition and the key condition ahead of the projection. The filter
fault also comes ahead of a key condition over the size limit.

When the table lookup fails, the handler now runs the tokenizer on the
filter first. The size check and the tokenizer on the key condition come
next, then the tokenizer on the projection. A table that exists keeps
the order of the checks. The engine test of a missing table and
tests/test_expression_leading_underscore.py get a row for each request.
The v1.1.0 release of 27 Nov 2026 does not include this change. Its
entry in the upgrade manual is now a v1.2.0 entry, after the two v1.2.0
entries of main. The entry names 1.1.0 as the release that served such a name.
It also names the Query filter and projection, which a table that does
not exist now checks too. The entry gets the PR and the issue numbers,
as the other entries have.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol

  1. e595aaf merges main at c8e66fb. It imports check_expression_size from extenddb_core::expression in crates/engine/src/query.rs and drops it from the crate::expression_helpers list, as you suggest. On the final head, the core lib tests pass (1260, 1 ignored) and the engine lib tests pass (984).
  2. The same merge takes the file of main for crates/engine/src/partiql/test_context.rs and makes context pub(crate). The PR body no longer has the line about a merge without a conflict.
  3. The merge brings in fix(core): read the latency segment clock through web_time #1482. The clippy step of wasm.yml is clean on the merged branch here, and the PR body no longer names the two commits of fix(core): read the latency segment clock through web_time #1482. The checks run again on the new head.
  4. I measured it in us-east-1 on 3 Dec, on a table that does not exist, twice each. With KeyConditionExpression pk = :v, FilterExpression _x = :v answers Invalid FilterExpression: Syntax error; token: "_", near: "_x". ProjectionExpression _x answers Invalid ProjectionExpression: Syntax error; token: "_", near: "_x". So e134cbd makes the missing-table branch run the tokenizer on the filter and on the projection too. The service answered the filter ahead of the key condition, and the key condition ahead of the projection. The branch checks them in that order. The engine test of a missing table and three new rows of tests/test_expression_leading_underscore.py test that order. 9e475b4 names the filter and the projection in the upgrade manual, in the entry that is now under v1.2.0. The docstring of the wire test names the Query projection.

@navareamol

Copy link
Copy Markdown
Collaborator

Points 1 to 4 of my review are resolved on 9e475b4. origin/main is an ancestor of the head, so there is no conflict and no import error. Core lib passes (1260), engine lib passes (984), the two wire files give 100 passed and 9 expected failures, and wasm, clippy and fmt are green. On a missing table the filter, then the key condition, then the projection answer in the order you measured. The upgrade manual entry under v1.2.0 matches the code. I found two things left.

  1. On a table that does not exist, a Query whose filter or projection is over 4096 bytes answers ResourceNotFoundException. For example KeyConditionExpression pk = :v with FilterExpression a = :v followed by 4100 spaces gets not found, and so does a valid key condition with ProjectionExpression a followed by 4100 spaces. On a table that exists the same two requests answer Invalid FilterExpression: Expression size has exceeded the maximum allowed size; and the same text for ProjectionExpression. The new branch runs check_expression_size on the key condition only. It also means a filter _x = :v followed by 4100 spaces gets the syntax error on a missing table and the size error on an existing one. Has anyone measured an oversize filter or projection on a missing table against the service? If it answers the size error, I think the branch needs the size check on the filter and on the projection, placed with their syntax checks. If it answers not found, I think the comment in handle_query and the PR text should say that only the key condition size is checked ahead of the lookup.

  2. The wire file has no row that puts a fault in the key condition and a fault in the projection together. The PR body lists _g = :v with projection _x as measured, and only the engine test pins it. When I moved the projection check ahead of the key condition, the engine test failed, and no row in tests/test_expression_leading_underscore.py covers that order. I think one more row in the file would close it.

I will approve once the first question is answered and the checks that are still running finish green.

… a missing table

On a table that does not exist, Query answered ResourceNotFoundException
to a filter or a projection over 4096 bytes. DynamoDB answers the size
error. Measured in us-east-1 on 4 Dec 2026, each request twice, with the
key condition `pk = :v`:

- FilterExpression `a = :v` and 4100 spaces: `Invalid FilterExpression:
  Expression size has exceeded the maximum allowed size;`
- ProjectionExpression `a` and 4100 spaces: `Invalid ProjectionExpression:
  Expression size has exceeded the maximum allowed size;`

The size error also comes ahead of the `_` refusal in the same member,
and the filter size error ahead of a key condition `_g = :v`. The key
condition `_g = :v` comes ahead of an oversize projection. Scan of a
table that does not exist sent the filter size error with no
`expression size` suffix too.

When the table lookup fails, the handler now checks the filter, then the
key condition, then the projection. Each one gets the size check, then
the tokenizer. The filter check uses ExpressionKind::Filter, so
size_error_includes_length no longer includes Filter. No other caller
checks the size as Filter: the filter parse checks it as Condition and
keeps the suffix (#1421). The engine test of a missing table gets four
rows. The wire file tests/test_expression_leading_underscore.py gets
three: the two size rows and the key condition ahead of the projection.
Main is at 5826e1b. This branch last had main at c8e66fb. Since
then, four PRs merged into main: #1446, #1531, #1466 and #1087.

One file conflicted. In docs/manuals/07-upgrade-manual.md, #1087 added
its v1.2.0 entry after the other v1.2.0 entries of main, where this
branch has its entry. The merge keeps the entries of main first, then
the entry of this branch.

Main changed no other file that this branch changes.
With the four rows of a6bf351, the test of a Query on a missing table
is 113 lines long. clippy::too_many_lines (pedantic) warns over 100
lines. The function holds one row per measured request, so it allows
the lint, as crates/core/src/backup_format/golden_tests.rs does for its
pinned lists.
… length

The doc of check_expression_size still named Filter and Condition as the
kinds whose size error carries the byte length. Since a6bf351, only
Condition does.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@navareamol

  1. I measured it in us-east-1 on 4 Dec, on a table that does not exist, twice each, with the key condition pk = :v. The filter a = :v and 4100 spaces got Invalid FilterExpression: Expression size has exceeded the maximum allowed size;, and the projection a and 4100 spaces got Invalid ProjectionExpression: Expression size has exceeded the maximum allowed size;. So the service checks the size ahead of the lookup. a6bf351 adds the size check to the filter and to the projection in the missing-table branch, each one ahead of its tokenizer. The order is filter, key condition, projection, and the service answered in that order:

    • _x = :v and 4100 spaces gets the filter's size error, so the size check comes ahead of the _ refusal. The same holds for the projection _x and 4100 spaces.
    • _g = :v with an oversize filter gets the filter's size error.
    • _g = :v with an oversize projection gets the key condition's syntax error.

    On a missing table the service sent the filter's size error with no expression size suffix, on Query and on Scan. The branch checks the filter as Filter, and size_error_includes_length no longer includes Filter, so the text matches. Scan of a missing table and the filter parse of an existing one keep the suffix, as on main (The expression size error on FilterExpression and ConditionExpression appends the byte length, which DynamoDB leaves out #1421). The engine test of a missing table gets four rows. tests/test_expression_leading_underscore.py gets the two _x size rows, and both fail with the missing-table branch of 9e475b4.

  2. a6bf351 adds that row too: query-key-condition-ahead-of-projection-missing-table, with _g = :v and the projection _x, which got the key condition's syntax error again on 4 Dec.

The checks at 9e475b4 finished with 75 of 75 passed. dd08869 merges main at 5826e1b, where #1087 put a manual entry at the place of this PR's entry, and the merge keeps both. ca7645b allows clippy::too_many_lines on the engine test, which the four rows take to 113 lines. 69e81e3 corrects the doc of check_expression_size, which still named Filter with Condition. The checks run again on 69e81e3.

@LJMart11 LJMart11 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Reviewed at 69e81e3. 1 finding: 1 Docs.

The change makes the expression tokenizer refuse a name that starts with _ (syntax error at the _, with the 1 validation error detected: prefix on PutItem, UpdateItem and DeleteItem conditions and UpdateItem update expressions), and makes Query check filter, key condition and projection size and tokens before reporting a missing table. Confirmed: the PR's dual-target wire file passes 49 of 49 on ExtendDB (SQLite) and 41 of 41 runnable rows pass on live DynamoDB (the 8 others are request shapes the live wrapper refuses); 37 extra probes (Query, Scan, GetItem, UpdateItem, PutItem and DeleteItem on existing and missing tables, with _ in functions, IN, BETWEEN, NOT, REMOVE, ADD, DELETE and legacy parameters) matched DynamoDB except the documented bare # and : windows and the size suffix. Putting back _ in is_ident_start, the Filter suffix, the PutItem count and the Query projection check each fails a test. Merged with current main (44a7b79) the tree builds and core (1260) and engine (984) lib tests pass under 1.94.0.

  • Docs crates/core/src/expression/kind.rs:41 — The doc says a filter parsed as Condition keeps ; expression size: N as DynamoDB sends it, but live DynamoDB sends no suffix for a Query or Scan filter on an existing table, and the head still appends it.

Comment thread crates/core/src/expression/kind.rs Outdated

/// Whether the size-limit error appends `; expression size: N`. Amazon
/// `DynamoDB` appends it for `Filter` and `Condition` only.
/// Whether the size-limit error appends `; expression size: N`. It does for

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Docs
The doc comment at kind.rs:41-47 and the body ("The filter parse on a table that exists checks it as Condition and keeps the suffix (#1421)") say DynamoDB's size error carries ; expression size: N for a filter that parse_condition_expr reads. I sent a 4106-byte filter (a = :v + 4100 spaces) to DynamoDB in us-east-1 on 2026-12-04: Query on an existing table, Query on a missing table and Scan on an existing table all answered Invalid FilterExpression: Expression size has exceeded the maximum allowed size; with no suffix. The head answers Scan with ... maximum allowed size; expression size: 4106 on both an existing and a missing table, so it also differs from the body's own statement that a Scan of a missing table gets no suffix.

Fix: reword the doc and the body so they do not claim the suffix is DynamoDB's for a filter, or drop Condition and the relabel inheritance from the set and measure each operation's condition separately; tests/test_expression_leading_underscore.py and query_missing_table_tests.rs:136 pin the current text and change with it. Only the wording is this PR's; the suffix behaviour on Scan and existing-table Query predates it.

Evidence: kind.rs:47 reads matches!(self, Self::Condition). On DynamoDB, PutItem with a 4107-byte ConditionExpression also answered 1 validation error detected: Invalid ConditionExpression: Expression size has exceeded the maximum allowed size; with no suffix, while the head answers ... size; expression size: 4107 without the count prefix.

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 a6bdace. The doc now names check_expression_size as the source of the error. It says that Amazon DynamoDB left the suffix out of the filter and condition errors that #1421 measured. In the description, What now says that ExtendDB keeps the suffix for a filter on a table that exists, and that #1421 tracks the difference.

On Scan, the description gives two answers. Why gives DynamoDB's answer to a Scan of a table that does not exist, with no suffix, and that sentence now names DynamoDB. Not in this PR gives ExtendDB's answer there, with the suffix (#1421), and the head sends that. Not in this PR now also says that a Query or a Scan filter on a table that exists gets the suffix.

The behaviour stays as it is. As you say, the suffix on Scan and on a Query of a table that exists predates this PR. #1421 proposes to drop it for every kind. Your PutItem request is the second row of #1421, which also names the missing count.

The doc of size_error_includes_length did not say whose error appends
`; expression size: N`, so it could read as the service's text. It now
names check_expression_size, and it says that Amazon DynamoDB left the
suffix out of the filter and condition errors that #1421 measured.

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.

ExtendDB accepts an attribute name that starts with an underscore in every expression, and DynamoDB refuses it as a syntax error

3 participants