Skip to content

fix(query): check legacy conditions against the key schema - #507

Open
LeeroyHannigan wants to merge 57 commits into
mainfrom
fix/legacy-condition-parity
Open

LeeroyHannigan wants to merge 57 commits into
mainfrom
fix/legacy-condition-parity

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

demohan reviewed bac8de51c on 25 November. The commits after it:

  • 2c73421a7 merges main at 5252eda31, after ci(fuzz): keep failing inputs out of public logs and artifacts #864, ci: raise the run-tests time limit from 15 to 20 minutes #895, test(storage-postgres): wait for the vector index hold release #929 and test(auth): pin the order of the scope date and token expiry checks #949 merged. No file conflicted, and main and this branch change no common file. On the merged tree, the core lib tests give 1190 passed and 1 ignored, and the engine lib tests give 947 passed. Against a SQLite server of the merge, tests/test_legacy_condition_parity.py gives 151 passed.
  • e1b6f79a7 adds rows that put a refused value inside NS, L and M, as demohan asked. The four values are NS [U+00E9], L [N U+00E9], M {k: N U+00E9} and L [N a then U+FF11], each in ScanFilter, QueryFilter and KeyConditions. On a table that does not exist, the service answers The parameter cannot be converted to a numeric value: é for the nine U+00E9 bodies. For the three a then U+FF11 bodies, it names a1 (measured 2026-11-25, two sends each). A SQLite server of 2c73421a7 gave the same answers. The wire test on a table that does not exist has the 12 rows in NOT_READ. The engine unit test has the four values in its table of refused values. With the rule of bfbf7e373 back for the numbers inside NS, L and M only, the 12 rows and the unit test fail. The other 151 wire rows pass. The doc of condition_values now lists the four shapes, and no other production line changed.

Testing done now gives the counts at e1b6f79a7.

demohan reviewed bfbf7e373 on 25 November. The commits from it to bac8de51c:

demohan's other point stays out of this PR. On a table that exists, a legacy value with U+FF11 or U+0661 reaches the storage layer as written, as on main. #565 tracks it and now lists demohan's shapes.

demohan reviewed 72b532417 on 24 November. The commits from it to bfbf7e373:

This body now gives the narrower rule in What item 1 and in the first Breaking changes bullet. It names #544's digit table under "Overlaps with other PRs". For the merge of main at 80490c6ca, it updates "Overlaps with other PRs".

What

Query checks the legacy KeyConditions and QueryFilter maps against the key schema before it reads any row, with the service's messages. Scan runs the same value checks on ScanFilter. The checks run in the engine, so every backend answers alike. Query runs them in the order the service reports them, except against the Select enum (see "Overlaps with other PRs"):

  1. Before the table lookup, validate_key_conditions checks each KeyConditions entry. Every number in the value list must parse, inside NS, L and M too. The check reads a Unicode decimal digit of the Basic Multilingual Plane as the digit it stands for, as the service does. It refuses every other character outside ASCII. A refusal names the value with those digits read. For a then U+FF11, it names a1. On a table that exists, a value with such a digit then reaches the storage layer as written, as on main (Unicode decimal digits in N values: refused on writes, compared as text on reads #565). Then it checks the operator name, the value count, the operator type, the value types and the BETWEEN range. An entry with NE, IN, NULL, NOT_NULL, CONTAINS or NOT_CONTAINS answers Attempted conditional constraint is not an indexable operation, on the hash key too.
  2. After the table and index lookup, desugar_key_conditions walks the keys in schema order. It reports an absent hash key first, then a value type that does not match the attribute definitions. The type message is Condition parameter type does not match schema type. After that it checks the hash key's operator, then an entry on a non-key attribute.
  3. After the Select checks, reject_empty_key_values refuses an empty S or B key value on every key schema, a GSI with several HASH or several RANGE attributes too. The message ends The AttributeValue for a key attribute cannot contain an empty string value. Key: <name>, or empty binary value on a B key. Then reject_query_filter_on_key refuses a QueryFilter entry on a key of the queried table or index.
  4. After the ExclusiveStartKey checks, validate_query_select_index_support refuses Select ALL_ATTRIBUTES on a GSI whose projection is not ALL.

BatchGetItem charges an absent key the minimum read, 0.5, or 1.0 with ConsistentRead, and keeps its table in ConsumedCapacity. validate_no_empty_key_value in extenddb-core is now pub, so the engine reuses the item-path check. The engine checks the numbers in legacy condition values with condition_values, a new pub function in crates/core/src/validation/number/operations.rs. condition_values reads each number of the value list with collect_numbers, folds its decimal digits with the function the engine passes, and words a fault with number_text(EmptyText::WithColon, ..). #620 added collect_numbers and number_text. The engine passes fold_decimal_digits of crates/engine/src/decimal_digits.rs, #544's digit table. docs/differences-from-dynamodb.md gets a Query and Scan section.

The review of the previous head, 5182292f5, listed seven items. Each has a fix below, measured against Amazon DynamoDB in us-east-1 on 2026-11-12 with two sends per request:

  1. Query refuses an empty key value on a GSI with several HASH or several RANGE attributes and answers the empty key message. It answered 200 before.
  2. Query reports the Select checks ahead of an empty key value. The old order reported the empty key value first.
  3. An empty number inside NS, L or M answers The parameter cannot be converted to a numeric value: , with the separator, as a top-level N "" does. The nested form had no separator until this change.
  4. Select ALL_ATTRIBUTES on a GSI whose projection is not ALL now comes after the key condition, Select, empty key, QueryFilter key and start key checks. The check had two call sites: one early, for a request without an ExclusiveStartKey, and one after the start key checks. It now has one call site, after the start key checks. Each request ran it once before and runs it once now.
  5. The non-indexable refusal runs once, at request time, before the table lookup. desugar_key_conditions no longer runs validate_key_conditions a second time. Four wire rows and two unit assertions check that position: a missing table, an unknown index, ConsistentRead on a GSI, and Select SPECIFIC_ATTRIBUTES without a projection.
  6. Tests cover B keys for the schema type check and for the binary wording of the empty key check. No production code changed for this item.
  7. When both key values are empty, the service names either key. 32 sends of one request named pk 12 times and sk 20 times. The wire assertion accepts either key. ExtendDB names the first key in schema order, and the differences document records that.

Why

Issue #477 lists eight differences on the legacy paths after #399. This PR fixes items 2 to 8. Item 1 is the choice of entry the service names when two legacy entries are both invalid. That changed between two runs of the same request, so no rule can encode it. The differences document records it.

This branch merges #399 at 5646709c6 and main. Main's PartiQL code from #411 calls parse_condition_expr, parse_update_expr and parse_optional_filter, which #399 replaced. Without #399's expression helpers, a merge of main alone does not compile. The diff of this PR shows #399's commits until #399 merges. The merge of main at 381c8c78a handles #1000's expression depth limit as #399 does: each call that is an operand counts one level, whatever its name. Past the limit, the parser checks the name of the call that crosses it. A call that the semantic pass refuses gets that refusal, as on the service (72b532417, measured 2026-11-19). #1155 lists three nests past the limit that still differ.

Closes #477

Overlaps with other PRs

Testing done

Run at e1b6f79a7, unless a bullet names another head or date:

  • cargo +1.97.0 fmt --all -- --check: pass.
  • cargo +1.97.0 clippy --locked --all-targets -- -D warnings on the six crates this PR changes (extenddb-core, extenddb-engine and the four storage crates) with extenddb-storage-cassandra/test-hooks,extenddb-storage-mongodb/test-hooks, on extenddb-engine with extenddb-engine/backup-test-hooks, and on extenddb-engine without its partiql feature: pass. The clippy step of .github/workflows/wasm.yml on extenddb-wasm-adapter for wasm32-unknown-unknown, with the two commits of fix(core): read the latency segment clock through web_time #1482 applied: pass. The test host has no clang, so that run used stand-ins for the C compile of the bundled SQLite, which clippy does not link.
  • cargo +1.91.1 check --locked -p extenddb-core -p extenddb-engine --all-targets: pass.
  • cargo +1.97.0 test --locked -p extenddb-engine -p extenddb-core --lib: core 1190 passed, 1 ignored. Engine 947 passed.
  • On a SQLite server and on a PostgreSQL server built from e1b6f79a7: tests/test_legacy_condition_parity.py, 163 passed on each.
  • python3 -m pytest --collect-only -q collects 7599 tests in tests/ and 672 in tests/python, with no error.
  • On a SQLite server built from 03d2d83db: tests/test_legacy_condition_parity.py, 115 passed. With 14 other query and scan wire files: 672 passed, 1 skipped. The skipped case runs only on MongoDB and Cassandra. The 14 files: test_query_scan.py, test_request_stage_checks.py, test_select_all_projected_attributes.py, test_gsi_multi_range_query.py, test_multipart_gsi.py, test_fgac_leading_keys.py, test_conditional_operator.py, the three test_dynamodb_attributes_*.py files, test_expr_operand_type_and_size.py, test_expression_param_usage.py, test_vector_index_query_scan.py and test_wording_parity_validation.py.
  • The measurement against Amazon DynamoDB in us-east-1 on 2026-11-12 covered 142 request shapes: the seven items with their controls, and related requests. Every shape went to the service twice, and the rows where the service names either key went 4 to 12 times. On 2026-11-12, ExtendDB answered 122 of them as the service does. The other 20 are differences this branch does not address, listed below.
  • The measurement against Amazon DynamoDB in us-east-1 on 2026-11-24 sent each body twice to a table that does not exist. One U+FF11 in KeyConditions, QueryFilter or ScanFilter answered ResourceNotFoundException, and abc in each map answered the number text. The SQLite server from 03d2d83db gives the same answers.
  • The measurement against Amazon DynamoDB in us-east-1 on 2026-11-25 sent 36 bodies twice each to a table that does not exist. In ScanFilter, QueryFilter and KeyConditions, the nine values that 11e50bcf7 refuses answered the number text, and U+FF11 inside NS, L and M answered ResourceNotFoundException. The SQLite and PostgreSQL servers from 08562698d give the same status, code and message for all 36 bodies.
  • A second measurement against Amazon DynamoDB in us-east-1 on 2026-11-25 sent 12 bodies twice each to a table that does not exist. In the three maps, they put U+00E9 inside NS, L and M, and a then U+FF11 inside L. Each answered the number text, with a1 for a then U+FF11. The SQLite and PostgreSQL servers from e1b6f79a7 give the same status, code and message for all 12 bodies.
  • On a SQLite server of 08562698d, legacy values with U+FF11 and U+0661 on a table that exists answer as on main. ScanFilter, QueryFilter and a GSI key condition give 200 with Count 0. An N sort key condition with EQ or BETWEEN gives 500. A SQLite server of 96713261a, before the fixes, answers the same. Unicode decimal digits in N values: refused on writes, compared as text on reads #565 tracks this.

The measurements also found these differences, which are outside this PR. The service's answer comes first in each:

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. The checks on legacy conditions run before the engine reads any row, with the service's messages. The wire protocol, the Storage trait, the auth model, the on-disk format and the CLI surface are unchanged.

Breaking changes

A SQLite build of main served some legacy requests that now get a ValidationException with the service's message:

  • An N value in ScanFilter or QueryFilter that the service cannot read as a number, inside NS, L and M too, such as abc or U+00E9. ExtendDB still serves a number written with Unicode decimal digits of the Basic Multilingual Plane, such as U+FF11, as main does.
  • An empty S or B key value in KeyConditions.
  • A KeyConditions value on a GSI key whose type is not the key's attribute definition type.
  • A QueryFilter entry on a key attribute of the queried table or index.

Other invalid legacy requests get the service's message in place of main's.


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.

…ts messages

Issue #108 lists 106 requests whose response differs from Amazon DynamoDB.
Every expectation in this change was measured against the service
(us-east-1, 2026-10-14); the probes and captured responses are in the
issue's notes, and every new test file was run against the service before
it was run here.

Semantic validation of expressions. After the grammar pass, the service
walks the parsed expression once, in expression order, checking each node
after its operands, then checks overlapping paths, then unused names and
values. A new `validate_update_semantics` and `validate_condition_semantics`
in the core crate follow that walk; the parsers now do grammar only, keep
function names as written, and record section order for the walk.

- UpdateExpression: `+` and `-` take numbers, `list_append` takes lists,
  `ADD` takes a number or a set, `DELETE` takes a set; a placeholder of the
  wrong type is refused with the service's type vocabulary (`S`, `N`, `L` for
  operators and functions; `STRING`, `NUMBER`, `Binary`, `BOOL`, `NULL`,
  `LIST`, `MAP` for ADD and DELETE). Function names are case-sensitive:
  `IF_NOT_EXISTS(x, :v)` and `foo(x)` are `Invalid function name`, a
  condition function is `not allowed in an update expression`,
  `list_append` is refused as an operand of a function or of `+`, both
  functions take two operands, the first operand of `if_not_exists` is a
  document path. A repeated section is reported after that section's own
  actions (`SET a = :v SET b = :q` reports `:q`). Previously `IF_NOT_EXISTS`,
  `DELETE s :string`, and `SET a = :string + :n` were accepted and written.
- ConditionExpression and FilterExpression: the six condition functions are
  matched as written (`ATTRIBUTE_EXISTS(pk)` was accepted and evaluated);
  `if_not_exists` and `list_append` are `not allowed in a condition
  expression`; a boolean function in operand position and `size` in
  condition position are `not allowed to be used this way`; operand counts
  are fixed per function; `attribute_exists` and `attribute_not_exists` take
  a document path; `begins_with` takes a string or binary and
  `attribute_type` a string naming a type, both checked at request time with
  the operation's prefix.
- Every unused name or value is listed in one set, sorted, so the message is
  the same on every backend; it named one key chosen by hash order.

Request stage on the read APIs. Query and Scan check the FilterExpression,
then the KeyConditionExpression (with its `Invalid KeyConditionExpression:`
prefix, and ahead of the key schema match, so an undefined `#n` is reported
as such), then the ProjectionExpression, then unused names and values, all
before the table is looked up. An undefined `:q` in a filter returned 200 on
an empty table. Limit and Segment checks precede the expressions on Scan.

Single-item order. UpdateItem checks the whole ConditionExpression before
the UpdateExpression. PutItem, UpdateItem, and DeleteItem wrap every
expression-stage error in `1 validation error detected: ` and omit the
`: ConditionExpression is null` suffix; the read, batch, and transaction
APIs return the messages bare. The ` expression size: N` suffix follows the
operation. Three existing dual-target tests asserted the unprefixed text and
fail against the service; they are corrected.

Transactions. TransactGetItems and TransactWriteItems validate in phases,
each over every item before the next: per item, expressions (UpdateExpression
before ConditionExpression), unused names and values, then the item's 400 KB
size; then table lookup; then the 4 MB total; then key schema, as a
cancellation with ValidationError on the first offending item only and None
on every other (it flagged every offender); then duplicates. An undefined
reference is the request error the service returns rather than a per-item
cancellation reason, and a key schema mismatch leaves other items'
conditions unevaluated. TransactWriteItems returns `"ItemCollectionMetrics":
{}` when SIZE is requested and no table has a local secondary index, and its
ConsumedCapacity entries are in first-appearance order rather than
per-process hash order.

Key-shaped messages. GetItem, DeleteItem, UpdateItem, BatchGetItem, and
BatchWriteItem (Put and Delete) refuse a key with a missing, mistyped, or
extra attribute with `The provided key element does not match the schema`;
PutItem keeps `Missing the key pk in the item` and `Type mismatch for key`.
BatchWriteItem returns `"ItemCollectionMetrics": {}` under SIZE with no LSI.

Table ARNs in `TableName` (eight #108 rows) stay unsupported by decision: an
ExtendDB table ARN names ExtendDB's account and region, so a table that
streams or replicates to Amazon DynamoDB would answer to two ARNs.
docs/differences-from-dynamodb.md records this.

Remaining #108 gaps after this change, all stated in the PR: the parser's
syntax wording (`Syntax error; token: X, near: Y`), the ResourceNotFound
message text, the 4 MB message (the service's carries its own payload size),
the service's rendering of over-limit list values, and the table ARN rows.

Testing: tests/test_transact_validation_order.py (31 cases),
tests/test_update_expression_rules.py (37), and
tests/test_expression_semantics.py (155) pass against the service and on
SQLite, PostgreSQL, and MongoDB; 164 of the 186 cases in the first and third
fail on main. The expression, validation, transaction, batch, query, and
scan suites pass on all three backends (767 on SQLite and PostgreSQL, 751 on
MongoDB with the four #387 cases unchanged). Of the 106 #108 rows, 83 now
return the service's status, error type, and message (30 on main). cargo
test --workspace 1,500 passed; fmt; clippy -D warnings on 1.97.0; cargo
+1.88.0 check.

Closes part of #108.
… three comments

The move of the FilterExpression operand-type checks into the semantic
pass dropped them for the legacy QueryFilter and ScanFilter parameters,
which bypass the parser. A ScanFilter with BEGINS_WITH and a number, or
LT and a boolean, was accepted at request time and refused only when a
row was evaluated, so an empty table returned 200. The desugared legacy
filter now runs the same begins_with and ordering operand checks as
before, with the FilterExpression prefix, before any row is read. Wire
tests cover both parameters on an empty table.

Comments reworded after review: the parsers state that grammar errors
are reported before semantic errors and why the semantic checks are
deferred; the empty operand list comment names the measured cases; the
PerTableCapacity doc states that first-appearance order is a firmer
guarantee than the service gives, with the measured orders.
…'s message

A ScanFilter or QueryFilter condition whose AttributeValueList holds a value of
a type its ComparisonOperator does not take is refused at request time with the
service's text, `One or more parameter values were invalid: ComparisonOperator
<op> is not valid for <type> AttributeValue type`, naming the first such value.
Measured against Amazon DynamoDB on 2026-10-23 on an empty table: BEGINS_WITH
with N, LT and GT with BOOL, and BETWEEN with L then N, which names the L. The
check runs in desugar_filter on each condition before it is desugared; the
`Invalid FilterExpression:` wording that the previous commit restored is gone.
attribute_type_code is exported from extenddb-core for the type tag.

Pin the condition-expression order for a syntax error after a semantic error:
`foo(pk) AND`, `ATTRIBUTE_EXISTS(pk) AND`, `begins_with(pk, :n) AND` and
`attribute_exists(#x) AND` each answer the syntax error on the service
(measured 2026-10-23), and the test asserts that no semantic message is
returned.

Document the order of ConsumedCapacity entries in transaction responses. With
two tables the service returned the same table first for both request orders
(measured 2026-10-23), so the order does not follow the request; ExtendDB keeps
first appearance in the request on every backend. No wire test asserts a
multi-table order.
… and messages

Measured the full ComparisonOperator by AttributeValue type grid against
Amazon DynamoDB on 2026-10-23 for ScanFilter, QueryFilter and KeyConditions,
with the value counts, mixed-type lists, inverted BETWEEN ranges and unknown
operator names. validate_legacy_condition in legacy_filter.rs now applies the
measured rules to every legacy condition before it is desugared and before the
table is looked up: the operator name (`Invalid comparison operator`), the
value count (`Invalid number of argument(s) for the <op> ComparisonOperator`),
the first value's type (EQ and NE take every type; BEGINS_WITH takes S and B;
CONTAINS and NOT_CONTAINS take S, N, B, BOOL and NULL; LE, LT, GE, GT, BETWEEN
and IN take S, N and B), that every value has the first value's type
(`AttributeValues inside AttributeValueList must be of same type`), and that a
BETWEEN lower bound is not above its upper bound. Each message carries the
`One or more parameter values were invalid: ` prefix. KeyConditions get the
same checks ahead of the table lookup, and a range key operator the service
does not index (NE, NULL, NOT_NULL, CONTAINS, NOT_CONTAINS, IN) is refused
with `Attempted conditional constraint is not an indexable operation`. The
engine's own count messages for these parameters are gone.

compare_orderable is exported from extenddb-core for the range check. The
grid is pinned in legacy_filter_tests.rs and one wire row per message in
TestLegacyFilterOperandType.

The ConsumedCapacity order note now cites the three-table measurement: 16
transactions in eight request orders all listed the tables in name order.
Amazon DynamoDB documents no order for the ConsumedCapacity entries of
TransactGetItems and TransactWriteItems. Measured on 2026-10-23 with three
single-hash-key tables whose names sort opposite to their creation order,
in three request orders: both operations listed the tables by creation
time, oldest first, whatever order the request named them in.

TableKeyInfo now carries the table's creation time. Every backend reads it
from the catalog row or document it already fetches for the key schema
(SQLite and PostgreSQL creation_date_time, MongoDB creation_date_time,
Cassandra created_at), so no request makes another catalog read.

PerTableCapacity moves from capacity_helpers.rs to per_table_capacity.rs,
takes the TableKeyInfo of each operation, and lists tables oldest first,
with name order breaking a tie on the same creation time. Both transaction
handlers use it, including the idempotent replay path of
TransactWriteItems, which now has a key_info accessor on PreparedOp.

tests/test_transact_capacity_order.py creates three tables whose names
sort opposite to their creation order, waiting for ACTIVE between them,
and asserts the order for both operations at TOTAL and INDEXES over the
three measured request orders; it runs against the service and against
ExtendDB. The row in docs/differences-from-dynamodb.md states the measured
order and ExtendDB's tie rule.
create_table wrote the catalog creation time as whole seconds, so two
tables created inside the same second carried the same value. The
transaction ConsumedCapacity order sorts tables by that value and falls
back to name order on a tie, which the service does not do, and
tests/test_transact_capacity_order.py failed 5 of 6 on this backend.

The write now keeps the millisecond part, which is the precision
bson::DateTime stores. Every reader already converts through
timestamp_millis, so DescribeTable, ListTables, the backup and restore
paths and the transaction key-info fetcher return the sub-second value,
the same as the PostgreSQL backend. Catalog rows written by earlier
builds keep whole seconds and can still tie.
The ConsumedCapacity order row said two tables created in the same
millisecond are listed in name order. The precision of the stored
creation time differs per backend, so the tie does too: nanoseconds on
SQLite, microseconds on PostgreSQL, milliseconds on MongoDB and
Cassandra, and whole seconds for a MongoDB catalog row written before
the precision fix. The row now says which, and names the backends the
order was measured on.

The service-side measurement no longer claims the three tables had a
single hash key, which the recorded run does not state. Same wording in
the test docstring and the PerTableCapacity doc comment.

The empty-operand-list comment in the condition parser now cites the
2026-10-23 measurement as well as the 2026-10-14 one.
semantics.rs had grown to 819 lines. It is now a module directory with
one file per rule family: update_rules.rs for the update-expression
rules, condition_rules.rs for the condition-expression rules, refs.rs
for the name and value usage checks both passes share, errors.rs for
the message builders, and tests.rs for the tests. mod.rs keeps the
module documentation, the two function-name tables and the two public
entry points.

No behaviour change. The functions moved unedited; the only edits are
the per-file imports, pub(super) on the helpers the siblings call, and
the test module's imports in place of its use super::*. The nine
semantic-pass tests keep their names and pass.
update_parser.rs had grown from 571 lines to 630. It is now a module
directory: mod.rs holds the parser at 417 lines and tests.rs holds the
21 tests at 215 lines.

No behaviour change. The test module moved unedited, keeping its
use super::*, and the tests keep their names. One comment inside it
lost an em dash.
The update-parser ADD/DELETE doc comment and the scan Segment check
comment carried an em dash. Both are now two clauses.
TransactWriteItems looked the tables up one item at a time and ran four
checks inside that loop, so the first item's defect hid a missing table on a
later item and the answer changed with the item order. The service reports
them in two places, measured with the items in each order.

Before any table is looked up, in the pass that also checks the expressions:
the nesting of every ExpressionAttributeValues value of the item, used or
not, on every kind of item (worded "ExpressionAttributeValues contains
invalid value: ... for key :v"), and for a Put the attribute name size, then
the item size, then the item nesting.

After every table is looked up and after the 4 MB total, in one pass over
the items in order: a key that does not fit the schema, then a key attribute
named in an Update (a ValidationError cancellation reason on that item, not
a top-level error), then an empty key value (a top-level
ValidationException). The first failing item decides. The empty value rule
is left out of the key shape check this pass uses, so a mistyped range key
is reported ahead of an empty hash key.

tests/test_transact_write_phase_order.py pins each placement with the items
in both orders, and the order of the checks inside one item.
check_key_condition_refs collected the references of a parsed
KeyConditionExpression into sets, sorted them, and named the smallest name,
then the smallest value. With two undefined references the message named an
alphabetical pick, and any name beat any value. The service names the first
reference in the text, names and values alike: "#b = :p AND #a > :q" names
#b, "#a = :p AND #b > :q" names #a, "pk = :q AND #n = :v" names :q, and
"pk = :z AND sk > :y" names :z.

parse_key_condition_expr now takes the request's expression maps and walks
the tokens in order once the grammar pass succeeds, so the order is the
text's. The separate check function and its call in Query are gone.

validate_refs_defined had no caller and documented an order it did not
implement (it sorted both lists); it is removed with its re-export.

tests/test_request_stage_checks.py pins the five expressions above on the
wire.
Four paths gave a text or an order the service does not.

A KeyConditionExpression clause with an identifier followed by "(" always
got "Invalid function name". The service answers by name. contains,
attribute_exists, attribute_not_exists and attribute_type get "Invalid
operator used in KeyConditionExpression" with no function name, on the sort
key and on the hash key. size gets "KeyConditionExpressions cannot contain
nested operations". Any other name, begins_with in another case included,
gets "Invalid function name; function: <name>". The text comes from
key_condition_function_refusal, next to the function name lists.

Scan answered "Value '0' at 'limit' ..." for a Limit under 1. The service
answers "Value at 'Limit' failed to satisfy constraint: Member must have value
greater than or equal to 1" for Scan as it does for Query, on an existing and
on a missing table, ahead of every expression error. Query already did.

An ADD with a string, map or boolean value, and a DELETE with a value that is
not a set, sent as legacy AttributeUpdates, went through the UpdateExpression
semantic pass and came back as "Invalid UpdateExpression: Incorrect operand
type ..." for a request that carried no expression. The service answers "1
validation error detected: One or more parameter values were invalid: ADD
action is not supported for the type S" and "... DELETE action with value is
not supported for the type N", ahead of the table lookup and key validation.
attribute_updates.rs checks the value types before the desugaring, in
attribute name order.

An empty ConditionExpression on a ConditionCheck was dropped as "no
condition" and then refused with a text the service does not use. The service
answers "Invalid ConditionExpression: The expression can not be empty;". Put,
Delete and Update still treat an empty string as no condition.

tests/test_request_stage_checks.py pins each of them on the wire, and unit
tests cover the function name texts and the value type texts.
Four comments described code that had moved or never worked that way.

scan.rs said Segment, Limit and Select are checked after the expressions.
Limit and the Segment range checks run first.

transact_get_items.rs said a ValidationError reason per offending item. Only
the first offending item carries one; every other item reports None.

storage-sqlite ddl.rs said the creation time column holds milliseconds,
while per_table_capacity.rs and the differences table said nanoseconds on
SQLite. CreateTable writes RFC 3339 with up to nanosecond digits, and the
value the transaction handlers order by is an f64 of epoch seconds, which
resolves about 0.24 microseconds. All three now say that.

The comments in transact_write_items.rs that called an empty or oversize key
an up-front top-level error went with the code they sat on in the commit that
moved the key checks.

validate_unused_attributes sorts the unused names and values so the message
is the same on every backend and process, and no test failed without the
sort. The new unit test builds fresh maps twenty times, each iterating in a
fresh random order, and expects {:a, :m, :z} and {#a, #m, #z}.
The first commit of this series checked every ExpressionAttributeValues
value of a transaction item against the item's nesting limit. That refused a
ConditionCheck value 32 wrappers deep, which the service accepts (an existing
test pins it). The service accepts 32 wrappers in an ExpressionAttributeValues
value and refuses 33, as a top-level ValidationException worded
"ExpressionAttributeValues contains invalid value: ... for key :v".
validate_expression_value_nesting_depth applies that threshold.

A value an Update stores with SET becomes an attribute of the item, so 32
wrappers pass that check and then break the item limit. The service answers a
TransactionCanceledException with a ValidationError reason "Nesting Levels
have exceeded supported limits" on every such item, after the lookup, the 4 MB
total, the key pass and the duplicate check. stored_value_nesting_reasons
reports it there. Before, the same value was refused as a top-level
ValidationException inside the table lookup loop, so a missing table on a later
item was hidden. The service also reports the other items' condition results
next to this reason; ExtendDB reports None for them, because no condition has
been evaluated at that point.

key_pass_failure now returns the whole list of reasons, so the handler no
longer builds it.

tests/test_transact_value_nesting.py pins the 31, 32 and 33 wrapper boundaries
for each place a value can sit and the position of the reason among the other
checks.
test_number_is_checked_before_the_table_lookup_and_select sends a
ScanFilter number that does not parse to a table that does not exist,
once without an IndexName and once with one. It sends no Select, so the
name claimed an order that the test does not check. The new name is
test_number_check_on_a_table_that_does_not_exist.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
…lookup

condition_values refused an N text that holds a character outside ASCII
before the table lookup, with the message it gives for abc. The number
rules read ASCII digits only. The service reads a Unicode decimal digit
as the digit (#565), and main let such a value reach the table lookup.

Measured on 2026-11-24 in us-east-1, two sends of each body, on tables
that do not exist:

- Query KeyConditions n EQ [N "\uff11"]: ResourceNotFoundException,
  "Requested resource not found"
- Query KeyConditions pk EQ [S "a"], QueryFilter x EQ [N "\uff11"]: the
  same answer
- Scan ScanFilter x EQ [N "\uff11"]: the same answer
- The same three maps with N "abc": "The parameter cannot be converted
  to a numeric value: abc"

condition_values now lets a number pass when the number rules cannot
read it and it holds a character outside ASCII. The check reads each
number of an N, NS, L or M value on its own. ExtendDB now answers the
three bodies as main and the service do. The engine unit test has the
U+FF11 row. The wire test on a missing table is now one data table: the
three rows, and the two abc rows that it held before.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
The condition parser checks the name of a call only when that call
crosses the depth limit, and the update parser does the same. The parse
stops there, so the semantic pass does not check the calls around it.
On a SQLite build of this branch, 150 nested foo( calls around size(a)
in a condition answer the depth error. So do 150 nested foo( calls
around if_not_exists(a, :v) in a SET value.

Six comments said that every call past the limit gets the name refusal.
They are the module docs of parser.rs, update_parser.rs and
depth_tests.rs, the comment in parse_operand, the doc of
parse_set_operand, and the doc of
calls_refused_by_name_past_the_limit_answer_the_name_refusal. They now
say that the parsers check the name of the call that crosses the limit,
and of no other call. The code does not change.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
Two places built the non-indexable refusal: validate_key_conditions and
the last arm of desugar_sk_condition. Its text is "One or more
parameter values were invalid: Attempted conditional constraint is not
an indexable operation". The Query handler runs validate_key_conditions
before desugar_key_conditions, so no request reaches that arm. Both
places now call not_indexable.

The unit test of the refusal also sends NE to desugar_sk_condition now,
and checks the same text. No answer changes.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
legacy_filter_tests.rs had 665 lines. The key schema helpers and the
four tests of the KeyConditions and QueryFilter key checks move with no
change to legacy_filter_key_schema_tests.rs. That file is a child module
of the test module. legacy_filter_tests.rs keeps the condition validator
tests, the number check test and the shared helpers, in 274 lines. The
new file has 402 lines.

The only new lines are the header of the new file and the mod
declaration. The engine unit tests are the same 885 tests.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
Main is at 018715e, three commits after the last merge (#690, #765 and
#774). One file conflicted: the docstring of
tests/test_expression_param_usage.py. #765 states that the values message
of a Scan or a Query whose AttributeValues parse has no suffix. This
branch adds the wrapped messages of the single-item writes. The merge
keeps both statements.

#765 also passes no expression parameters to the values check in
handle_scan, which merged clean. So the row of
tests/test_expression_semantics.py that sends a Scan with a
ProjectionExpression and ExpressionAttributeValues now expects the message
with no suffix. The service answered that request with the same message,
on a table that does not exist, on 24 November 2026, each request sent
twice.
Main is at 3534c9e, two commits after the last merge (#1280 and
#1009, the WebAssembly build). One file conflicted:
crates/engine/src/lib.rs. In the module list, this branch adds
attribute_updates and per_table_capacity, and #1009 puts a wasm32 cfg on
backup and private_fs and adds pre_dispatch. The merge keeps all of
them in name order, with each cfg and comment of #1009 above its
module.

Main changed two other files that this branch changes, and git merged
them with no overlap. crates/core/src/limits/mod.rs gains page_size.
The Limit conversion in crates/storage-sqlite/src/data/query_scan.rs
saturates where usize is 32 bits. #1280 changes only
crates/storage-mongodb/tests/migrations_guards.rs, which this branch
does not change.
The WebAssembly job builds extenddb-engine without its partiql
feature. The workspace depends on the engine with
default-features = false, and the wasm adapter does not enable
partiql. On this branch, strip_single_item_write_prefix and
parse_update_expr have callers only in the PartiQL module. So that
build reports both as never used, and the clippy step of the job fails
with -D warnings.

Both now carry #[cfg_attr(not(feature = "partiql"), allow(dead_code))],
as int32_member::read does on main. A build with the feature does not
change.

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

The depth comment item is resolved: 087f851 rewrites the six comments to say only the call that crosses the limit is checked by name, and on a SQLite server built from this head 150 foo( around size(a) or if_not_exists(a, :v) answer the depth error and 151 answer Invalid function name; function: foo, twice each. The U+FF11 and U+0661 shapes 12d210d aims at, 1.5 and 1E2 included, answer ResourceNotFoundException on a missing table as the service in us-east-1 does, 29 shapes, and abc still answers the number sentence everywhere. The not_indexable refactor, the test file move, the merges and the other commits change no answer: 24 operator shapes, the earlier items 1 to 4 and 7, the depth probe and the order probe answer as at 72b5324. fmt, clippy with and without partiql, and the 1.91.1 MSRV build are clean, the workspace tests pass apart from the host's secmem memlock test, test_legacy_condition_parity.py passes 115 of 115, CI is green on 65 checks, and the three new negative controls fail as they should.

I will approve once the non-ASCII exception is limited to the digits the service reads.

.into_iter()
.try_for_each(|n| match normalize_number(n) {
Ok(_) => Ok(()),
Err(fault) if fault.is_not_a_number() && !n.is_ascii() => Ok(()),

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.

!n.is_ascii() lets every unreadable number with a character outside ASCII through, not only Unicode decimal digits. The service refuses é, 1é, a1, ², ½, Ⅰ, -1, 1.5 and the non-BMP digit 𝟏 (U+1D7CF) with The parameter cannot be converted to a numeric value: <value>, in ScanFilter, QueryFilter and KeyConditions and inside NS, L and M, and 72b5324 answered each the same way. This head answers ResourceNotFoundException on a missing table, 200 with Count 0 on an existing one, 500 InternalServerError on a numeric sort key or a BETWEEN on one, and the operator or Select sentence beside NE, a bad operator or SPECIFIC_ATTRIBUTES without a projection. That is 86 shapes, two sends each to the service, 72b5324 and this head, with the same answers on SQLite and PostgreSQL. Passing only text made of BMP decimal digits in a well-formed number matches all 181 shapes probed; the decimal digit table on #544 and #1364 is not on this branch. With the branch removed only the U+FF11 unit row fails, so a row with é would hold it. The doc above (:176), legacy_filter.rs:528, the body's What item 1 and Breaking changes bullet 1 describe the wider rule.

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 11e50bc. condition_values now folds the Unicode decimal digits of the Basic Multilingual Plane to ASCII digits, then applies the number rules. The rules refuse any other character outside ASCII. The fold is #544's crates/engine/src/decimal_digits.rs, copied byte for byte, so whichever of the two PRs merges second drops its copy.

On 2026-11-25 I sent the nine values to the service on a table that does not exist, twice each, in ScanFilter, QueryFilter and KeyConditions. Each answers The parameter cannot be converted to a numeric value: <value>. For a then U+FF11 the value comes back as a1, and the check names it the same way.

The unit test has a row for each value beside the U+FF11 row. The wire test on a table that does not exist has the 27 rows. With !n.is_ascii() back in place, the 27 wire rows fail and so does the unit test. The doc at :176, the comment in legacy_filter.rs, What item 1 and the first Breaking changes bullet now give the narrower rule.

Comment thread crates/engine/src/legacy_filter.rs Outdated
/// 1. every `N` in the value list, including inside `NS`, `L` and `M`, is a
/// valid number (`The parameter cannot be converted to a numeric value:
/// <raw>`, or the overflow, underflow and 38-digit messages; no prefix),
/// or holds a character outside ASCII (see `condition_values`);

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.

On a table that exists, 1 and ١ now reach storage and answer wrongly: 200 with Count 0 on the filters and a GSI key, where the service returns the item, and 500 on KeyConditions sk EQ, sk BETWEEN and sk BETWEEN [1E2, 5]. 72b5324 answered these with the number sentence, also wrong, and main answers as this head does, 32 shapes in all. This fits #565 if it stays out of this PR, and #565 can list these shapes.

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.

This stays out of this PR, and #565 now has these shapes. I ran them again on a SQLite server of 0856269. They answer as on main. U+FF11 and U+0661 get 200 with Count 0 in ScanFilter, QueryFilter and a GSI key condition. On an N sort key, sk EQ and BETWEEN get 500.

@@ -0,0 +1,274 @@
// Copyright 2026 ExtendDB contributors

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.

No row puts U+FF11 inside NS, L or M; this head answers those as the service 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.

Added in 0856269: U+FF11 inside NS, L and M, in each of the three maps, in the wire test on a table that does not exist. The service answers ResourceNotFoundException for all nine bodies (2026-11-25, twice each), and so does this branch. The unit test checks the three values beside the U+FF11 row.

Main is at a417b2f, two commits after the last merge (#596 and
#1173). No file conflicted. Main and this branch change one common
file, crates/storage-cassandra/tests/common/mod.rs, in different
hunks. #1173 reads the account keyspaces through a workers helper, and
this branch adds creation_date_time to the test tables.
…igits

12d210d let every legacy N text with a character outside ASCII reach
the table lookup when the number rules could not read it. The service
reads a Unicode decimal digit of the Basic Multilingual Plane as the
digit (#565). Before the table lookup, it refuses the other characters
outside ASCII below.

Measured on 2026-11-25 in us-east-1, two sends of each body, on a table
that does not exist, in ScanFilter, QueryFilter and KeyConditions:

- N "\u00e9", "1\u00e9", "\u00b2", "\u00bd", "\u2160", "\uff0d1",
  "1\uff0e5" and "\U0001d7cf": "The parameter cannot be converted to a
  numeric value: <value>", with the value as sent
- N "a\uff11": the same text, with "a1"

condition_values now reads each number through a fold of those digits
to ASCII digits, and checks the result with the number rules. A refusal
names the folded text, as the service does. The fold is the digit table
of #544, crates/engine/src/decimal_digits.rs. This commit adds that file
byte for byte, with the same mod line, so the second of the two PRs to
merge drops its copy. extenddb-core cannot call the engine, so the
engine gives the fold to condition_values.

The engine unit test and the wire test on a table that does not exist
have a row for each of the nine values. With the old condition back in
condition_values, the "\u00e9" rows fail.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
No test put a Unicode decimal digit inside an NS, an L or an M value of
a legacy condition. Measured on 2026-11-25 in us-east-1, two sends of
each body, on a table that does not exist, in ScanFilter, QueryFilter
and KeyConditions:

- NS ["\uff11"], L [N "\uff11"] and M {"k": N "\uff11"}:
  ResourceNotFoundException, "Requested resource not found"

ExtendDB answered the nine bodies the same way before this commit.

The wire test on a table that does not exist has the nine rows. The
engine unit test checks the three values beside the U+FF11 row.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
Main is at 80490c6, six commits after the last merge (#398, #428,
#544, #567, #584 and #588). One file conflicted:
crates/engine/src/query.rs.

This branch moves the table lookup, the index lookup and the index key
schema below the request-stage checks. #544 moves the Limit check and
the parameter mix check into validate_query_request_body, which reads
the raw body before deserialization. Three conflict hunks in
handle_query follow from this:

- After deserialization, this branch keeps the Limit check and main
  keeps the table lookup. The merge keeps the lookup where this branch
  has it and puts the comment of #544 in place of the Limit check.
- Next, this branch keeps the variables of the mix check and main keeps
  the index key schema. The merge keeps the key schema where this
  branch has it. It drops the mix check variables, which nothing reads
  now, and keeps the comment of #544 and has_cond_op.
- Before the ExclusiveStartKey check, this branch removes the filter
  operand checks, because its semantic pass runs them at parse time.
  #544 adds validate_key_condition_types there. The merge keeps the
  type check and drops the filter checks.

#544 refuses a begins_with value that is not an S or a B ahead of an
unused value (rows q5 and p4 of tests/test_query_key_value_types.py,
measured 2026-11-06). This branch checks unused values before the
table lookup, so the merged code gave the unused value message for
those two rows. The merge calls refuse_begins_with_on_number after the
key condition parse and removes the later call. The values of legacy
KeyConditions pass validate_key_conditions before that point.

Git merged four other files that both sides change, with no overlap:
crates/core/src/expression/key_condition.rs, crates/engine/src/lib.rs,
docs/differences-from-dynamodb.md and crates/engine/src/decimal_digits.rs,
which both sides add with the same content.
…te tests

#544 adds a TableKeyInfo literal to the test context of
crates/engine/src/query_gate_tests.rs. The commits of #399 on this
branch add the creation_date_time field to TableKeyInfo. So the engine
tests do not compile after the merge of main at 80490c6. The literal
now sets creation_date_time to 0.0, as the other test literals on this
branch do.

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

The non-ASCII rule matches the service at 0856269; bac8de5 merges main, which now carries decimal_digits.rs, and adds one field to a test literal. The 181 shapes from the earlier round, sent twice each to the service in us-east-1 and to SQLite and PostgreSQL servers built from this head, answer as the service does: the 86 that 72b5324 broke, such as ScanFilter x EQ [N "é"] on a missing table with The parameter cannot be converted to a numeric value: é, and the 29 U+FF11, U+0661, 1.5 and 1E2 shapes with ResourceNotFoundException. Of 237 new shapes, digit one and nine from each of the 37 BMP digit ranges read as digits, the 8 characters beside those ranges are refused, the refusal names the folded text (1é as 1é, a١ as a1), and 39 fullwidth digits, 1E126 and 1E-131 get the 38-digit, overflow and underflow messages, inside NS, L and M too; 220 of 237 match the service, none that matched at 72b5324 differs here, and 107 that did not now match. PostgreSQL answers as SQLite on all 418.

The 41 missing-table rows match the service twice each, restoring the old !n.is_ascii() rule fails the unit test and the 27 refused rows, removing the fold fails the 12 digit rows and the 3 a_ff11 rows, and the U+FF11 rows inside NS, L and M fail with only top-level values folded. The docs and the body describe the rule the code applies, fmt, clippy and the 1.91.1 check are clean, and core (1179) and engine (909) pass. #565 now lists the existing-table shapes.

I will approve once a refused non-ASCII value inside NS, L or M has a row.

# Measured 2026-11-25: the service refuses the other characters outside ASCII
# here before the table lookup, and names the value with its decimal digits
# read. (id, N text, the text the message names)
NOT_READ = [

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.

No row refuses a non-digit non-ASCII character inside NS, L or M, a position the operations.rs:194 comment names. With the pass rule from bfbf7e3 brought back for nested numbers only, the legacy_filter unit tests and all 151 wire rows pass, and ScanFilter NS ["é"] on an existing table answers 200 Count 0. This head is right: NS ["é"], L [N "é"] and M {k: N "é"} in all three maps answer The parameter cannot be converted to a numeric value: é on the service and here, and L [N "a1"] answers with a1, 12 shapes twice each. Rows for these in NOT_READ and in the unit test would hold it.

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 in e1b6f79. NOT_READ in tests/test_legacy_condition_parity.py now holds the whole value, and it has four more values: NS ["é"], L [N "é"], M {k: N "é"} and L [N "a1"]. Each one runs in ScanFilter, QueryFilter and KeyConditions on a table that does not exist, so the wire test has 12 new rows. The table of refused values in numbers_are_checked_before_the_operator_checks has the four values too, and the doc of condition_values lists them.

On 2026-11-25 I sent the 12 bodies to the service, twice each. The answers match yours: The parameter cannot be converted to a numeric value: é, and a1 for L [N "a1"]. The SQLite and PostgreSQL servers of this head give the same answers.

With the pass rule of bfbf7e3 back for numbers inside NS, L and M only, the 12 new wire rows fail, and so does the unit test. The other 151 wire rows pass.

Main is at 5252eda, four commits after the last merge (#864, #895,
#929 and #949). No file conflicted. Main and this branch change no
common file.
No test refused a character outside ASCII inside an NS, an L or an M
value of a legacy condition. Measured on 2026-11-25 in us-east-1, two
sends of each body, on a table that does not exist, in ScanFilter,
QueryFilter and KeyConditions:

- NS ["\u00e9"], L [N "\u00e9"] and M {"k": N "\u00e9"}:
  ValidationException, "The parameter cannot be converted to a numeric
  value: \u00e9"
- L [N "a\uff11"]: the same message for "a1"

ExtendDB answered the 12 bodies the same way before this commit.

The wire test on a table that does not exist has the 12 rows. Each row
of NOT_READ now holds the whole value, as DIGITS_READ does. The engine
unit test checks the four values in its table of refused values. The
doc of condition_values lists the four shapes.

With the rule of bfbf7e3 back for numbers inside an NS, an L or an
M, the 12 rows and the unit test fail. Under that rule, a value that is
not a number passes when it holds a character outside ASCII.

Signed-off-by: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com>
rlunar pushed a commit to rlunar/extenddb that referenced this pull request Nov 25, 2026
…rules (ExtendDB#544)

* fix(query): check Query values against the key schema and the number rules

A Query with a KeyConditionExpression did not check a key condition value's
type against the key attribute's AttributeDefinitions type, and did not check
that an N value in ExpressionAttributeValues is a number. The storage layer
compared the value's inner text with the stored key and ignored the type tag,
so {"N": "bob"} on an S partition key read the bob partition while
authorization bound no dynamodb:LeadingKeys value to it, and a sort key value
of another type answered InternalServerError on SQLite.

Add the two checks the service applies before it reads a row, on the
expression path (crates/engine/src/query_key_values.rs):

- an N value in ExpressionAttributeValues that is not a number answers
  "The parameter cannot be converted to a numeric value: <value>" (the
  overflow and 38-digit texts for those cases; an empty value answers the
  message with the colon). The check covers the whole map, including NS
  members and values nested in L and M, whether the key condition, the
  filter or nothing reads them, with the walk PutItem and UpdateItem already
  use. It runs at request time after the Limit and expression parameter mix
  checks and before the table lookup, which moves those two checks ahead of
  the table lookup as well. The server runs the same request-time checks
  ahead of the IAM decision, so a principal under any LeadingKeys fence form
  gets ValidationException and no items;
- a key condition value whose type is not the key attribute's type answers
  "One or more parameter values were invalid: Condition parameter type does
  not match schema type", for the partition key, the sort key under every
  comparison operator, both BETWEEN bounds, the begins_with prefix and
  multi-attribute index keys, after the key schema, filter, projection,
  unused value and Select checks and before the ExclusiveStartKey check. When
  a compared placeholder is undefined the check returns without a verdict and
  the undefined placeholder is reported.

Measured on the service on 2026-10-24 (113 requests, each sent twice). The
legacy KeyConditions path is unchanged; its checks land with ExtendDB#507. Scan is
unchanged. Unit tests at the checks and a dual-target wire test file,
tests/test_query_key_value_types.py, which fails on main.

* fix(query): run the request-time checks on the raw body, enums in the service's order

The server ran its pre-IAM checks only when the body deserialized as
QueryInput, and the engine checked the ReturnConsumedCapacity and Select
enums before them, so a Query carrying an invalid Select and an N value
that is not a number answered the Select message, or AccessDeniedException
for a principal whose LeadingKeys fence needs a value. The checks now read
the raw body in the service's order, measured 2026-10-24: Limit, the
expression and non-expression parameter mix, ReturnConsumedCapacity, every
number in ExpressionAttributeValues, then Select. The engine and the server
run the same function.

* docs(query): name the request-time function in the comments that point at it

* fix(cassandra): pass the bare index name in IndexNotFound so the Query sentence matches the other backends

* fix(query): accept Unicode decimal digits in the number check and report a shape fault ahead of the request-time checks

The request-time number check refused an N value written with a Unicode
decimal digit (fullwidth, Arabic-Indic, Devanagari) that the service accepts
as the digit it stands for, so a Query that returns rows on the service
answered ValidationException here. The check now folds every general
category Nd digit to ASCII before the number rules run and echoes the value
as the request wrote it when the rules refuse it; the Nd zero code points of
Unicode 15.0 live in a module of their own. The fold applies to the check
only: the handler and the server's key binding read the value as written.
The write paths are unchanged.

The checks run on the raw body before deserialization, so a field of the
wrong JSON type elsewhere in the body (a string ExpressionAttributeValues
beside a Limit of 0, a string ExpressionAttributeNames beside a malformed N,
a numeric Select) answered the check's ValidationException where the service
and the previous release answered SerializationException. When a check fails,
the body is now deserialized as the typed input and a SerializationException
from that is returned instead; a ValidationException the deserializer raises
does not preempt the check, and a body that passes every check is not
deserialized twice. The server's call before dispatch goes through the same
function.

Measured against the service on 2026-10-25 (11:31 UTC) on tables with S/N
and S/S keys, each request twice. Unit tests cover the digit table, the
folded check and the shape-fault order; the wire file gains the measured
rows for both.

* fix(query): leave an unknown type descriptor to the request-time checks, and assert only acceptance for Unicode digits

The shape-fault pass returned the deserializer's SerializationException for an
AttributeValue with an unknown type descriptor, so Limit 0 beside {"X": "1"}
changed class. The service answers the Limit ValidationException for that
body (measured 2026-10-25), and the check's answer is returned again.

The Unicode digit tests asserted that a key condition or filter written with
a Unicode digit reads the item stored with the ASCII digit. This change makes
the request-time check accept such a value; it does not change how the
handler reads it, so the tests assert only that the value is accepted. A new
test checks that a partition key value written with Unicode digits returns no
item of a partition a ForAllValues LeadingKeys fence keeps the caller from.

* test(query): say which Limit text the service uses beside an unknown type descriptor

* test(query): pass the RANGE attributes to resolve_multipart

Main changes resolve_multipart to take the HASH and the RANGE attribute
names (ExtendDB#429). The multi-attribute HASH test now gives r as the RANGE
attribute, as its attribute definitions do.

* fix(query): order the key value type check and the begins_with refusal as the service does

On a single-attribute key schema, the later check of this branch now reports a
wrong type in a key condition expression, as the service does. The early check
from main still runs there for legacy KeyConditions, which the later check
skips. The begins_with refusal now reads the type of the value instead of the
type of the sort key.

* test(query): pin begins_with on a non-key attribute and correct the order comments

Two new rows send begins_with with an N value on an attribute that is not in
the key schema. One row uses a table with an S sort key and the other uses a
table with an N sort key. The service refuses both requests with the
begins_with operand type message.

The comments in handle_query now say that the classifier checks the values of
legacy KeyConditions. They also say which attribute definitions it uses for
each kind of key schema. The doc of resolve_key_schema_with now says where the
service reports a wrong type on a single-attribute key schema (measured
2026-11-06).

* fix(query): check each value on its own and answer in the service's order

- Report an invalid ReturnConsumedCapacity ahead of the expression and
  non-expression parameter mix.
- Check the numbers in each ExpressionAttributeValues entry on its own. A
  value that does not deserialize no longer turns the check off for the
  others, in the handler and before authorization.
- Beside a value the service cannot read as one type, answer in the
  service's order. Such a value is a null, or holds no known type
  descriptor, more than one, or an unknown one beside a known one. Select,
  ReturnConsumedCapacity and Limit come together, with the Limit text that
  names the value. The parameter mix comes next, then the first value with
  a fault and its placeholder. A value the service cannot read comes ahead
  of a number fault in another value.
- In the shape fault check, replace only the parts of such a value that the
  service cannot read. A field of the wrong JSON type in the rest of the
  value still answers SerializationException.
- Count a decimal digit only below U+10000, as the service does. The check
  refuses a digit from U+104A0 up.
- Echo a refused number with each decimal digit folded to ASCII.
- Add rows for legacy KeyConditions and for a multi-attribute key schema
  beside a non-key clause. Skip the second type check where the classifier
  checked the values.
- Delete the LeadingKeys test tables when a call raises.
- Give the checks for values the service cannot read their own module and
  tests. Move the request order unit tests and the shape fault and
  LeadingKeys Python tests to files of their own.

* fix(query): share the key value type check and update three comments

The comment above the Query request checks in authorize_request said
that they run for every principal. They run after the cross-account
refusal, so a table ARN in another account gets AccessDeniedException
without them. The service runs them first for a body it can read. Main
has the same order for every Query check, and the call does not move.
The comment now states this.

The comment above the key value type gate in handle_query now states
the service's order for legacy KeyConditions. For a legacy value of the
wrong type on a single-attribute key schema, the service reports the
projection, Select, filter, QueryFilter and unused-value checks first.
The classifier's check answers ahead of them, as on main.

The doc comment of the Query number check is about the
ExpressionAttributeValues contains invalid value wrapper. It said that on
Query the service adds the wrapper only for a value it cannot read as one
type. The service also adds it beside a Limit above 2147483647 (measured
2026-11-12), and the comment now says so.

validate_key_condition_types now calls check_key_value_type for each
value it compares. This removes type_matches and resolve_attr_name,
which repeated check_key_value_type and resolve_path_attr_name.
check_key_value_type returns KEY_CONDITION_TYPE_MISMATCH in place of a
second copy of the text. No answer changes.

validate_attribute_number in the core validation module is private
again. An earlier commit of this branch made it public, and nothing
outside that file calls it.

* fix(query): read each payload of a value with several types first

first_fault returned the more than one datatypes text as soon as a value
held two type descriptors. It did not read their payloads. The service
reads every payload first. On Query, the service gives one answer for
:v set to {"N": "bob", "S": "x"} and for {"S": "x", "N": "bob"}. The
answer is "ExpressionAttributeValues contains invalid value: The
parameter cannot be converted to a numeric value: bob for key :v".
{"N": "1", "S": "x"} answers the more than one datatypes text. The
service names a null or an empty value inside an L beside an S in the
same way. It reads N ahead of NS, and NS and M ahead of L, in either
member order (each request measured twice on 2026-11-19).

first_fault now reads the payloads in the order of TYPE_DESCRIPTORS,
which agrees with those pairs. It returns the more than one datatypes
text only when no payload has a fault.

The doc comment of the Query number check said that the service adds
the wrapper on UpdateItem. On the service, :v set to {"N": "bob"} in
UpdateItem gets no wrapper, in SET a = :v and in a ConditionExpression
that reads :v. The answer is "1 validation error detected: The
parameter cannot be converted to a numeric value: bob". The comment no
longer names UpdateItem.

* fix(query): check ExpressionAttributeNames ahead of the numbers

The request-time Query checks had no ExpressionAttributeNames step, so an
invalid names key beside {"N": "bob"} answered the numeric text. The
service and main answer `ExpressionAttributeNames contains invalid key:
Syntax error; key: "a"`.

validate_names runs the ExpressionAttributeNames deserializer on the raw
body and returns its ValidationException. Both paths of the checks call it
after the parameter mix and ahead of the values.

The service checks in the same order: it reports a Limit of 0, an invalid
ReturnConsumedCapacity and the mix ahead of an invalid key. The key comes
ahead of an N value that is not a number and of a duplicate NS. It also
comes ahead of an invalid Select and of a value the service cannot read as
one type. With KeyConditions and no KeyConditionExpression, the service
still reports the key. Each request went to the service twice on
2026-11-19, with the names map first and last in the body.

* fix(query): read a null payload as no payload

On Query, {"S": null} beside an invalid Select answered
`SerializationException: S value must be a string`. The request checks
read {"S": null} as an S, so the Select check failed. The shape fault check
then read the S payload as a JSON type fault. Main answers the Select text,
as the service does.

The service reads a type descriptor with a null payload as absent. To the
service, {"S": null} is a value it cannot read as one type, and the request
takes that order of checks. Beside an invalid Select it answers the Select
text. Beside a Limit of 0 it answers the Limit text that names the value.
Alone it answers `ExpressionAttributeValues contains invalid value:
Supplied AttributeValue is empty, must contain exactly one of the supported
datatypes for key :v`. The service accepts {"S": null, "N": "1"} in a
FilterExpression. Each request went to the service twice on 2026-11-19.

unreadable counts a type descriptor with a null payload as a part the
service cannot read, while first_fault and make_readable skip it.

* fix(query): report an empty name after a value the service cannot read

On Query, an empty name in ExpressionAttributeNames beside a value the
service cannot read as one type answered the empty name text. The service
answers the value's text. For {"#a": ""} beside {"X": "1"} it answers
`ExpressionAttributeValues contains invalid value: Supplied AttributeValue
is empty, must contain exactly one of the supported datatypes for key :x`.
Beside {}, {"N": "1", "S": "x"}, a null and {"S": null}, the same names map
answers that value's text. Beside {"X": "1"}, {"#a": "", "b": "c"} answers
`ExpressionAttributeNames contains invalid key: Syntax error; key: "b"`.
Beside {"S": "a", "X": "1"}, which has no fault of its own, {"#a": ""}
answers the empty name text. Each body went to the service twice, with the
names map first and last, on 2026-11-19.

On that path the service checks the keys of the names map ahead of the
values. Those checks refuse an invalid key, a key over 255 bytes and an
empty map. The service makes the empty name check after the values.
unreadable_value_checks now runs the key checks ahead of the values. It
runs them through the same deserializer, with each name replaced. The whole
names check runs after the values.

The unit tests share one set of message texts, and the names tests are one
table of rows. The handler and pre-IAM comments point to
validate_query_request_body, whose doc lists the order of the checks.

* docs(query): scope four comments on the names checks

The doc of validate_query_request_body said that the service makes the
request-time checks first on a Query that names a table ARN in another
account. The measurement covers a body the service can read, and the
doc now says so.

The doc of validate_names now lists the check on a key over 255 bytes,
which the deserializer makes and which validate_name_keys names. Step 5
of the unreadable_value_checks doc is three sentences. The first list in
the docstring of TestExpressionAttributeNamesOrder now covers readable
values only. The docstring also gives the place of the key checks beside
a value the service cannot read. No code or test row changes.

* refactor(query): take three message texts from core

query_key_values.rs kept private copies of three texts that core already
defines: NOT_A_NUMBER of the number check, and EMPTY_ATTRIBUTE_VALUE and
MULTI_ATTRIBUTE_VALUE of the AttributeValue deserializer. Core now makes
the three public, and the Query check imports them. The texts do not
change.

NULL_VALUE and TYPE_DESCRIPTORS stay in query_key_values.rs. Core's only
copies are private constants of its partiql module. A build without the
partiql feature leaves that module out, and the engine builds without the
feature.

* docs(query): give the M member order of the MongoDB build

The doc of first_fault said that it visits M members in key order,
because serde_json keeps the members of an object sorted by key. The
MongoDB build turns on the preserve_order feature of serde_json through
bson, so that build visits the members in document order. The docs of
first_fault and Fault, and step 4 of the unreadable_value_checks doc, now
give the iteration order of the map. No code changes.

* test(query): give the service's text for each shape fault row

TestShapeFaultsAreReportedFirst asserts the error type only, because the
SerializationException texts of the service differ from those of
ExtendDB (ExtendDB#1012). Each row of SHAPE_FAULTS now has a comment with the
message of the service, from the measurements of 2026-10-25 and
2026-11-11. No row changes.

* docs: list three Query differences from DynamoDB

docs/differences-from-dynamodb.md gets a Query section. Its rows give the
order of the cross-account refusal and the request checks (ExtendDB#974), and N
values written with Unicode decimal digits (ExtendDB#565). A third row gives the
wrapper that the service adds beside a Limit above 2147483647 (ExtendDB#976).

* fix(query): find a shape fault in any member and value

When a request-time check fails, validate_query_request_body looks for a
member of the wrong JSON type, because the service reports one ahead of
the checks. It deserialized the whole body once, and serde stops at the
first member that fails, in map order. An empty NS in
ExpressionAttributeValues stopped it, so Select: 5 beside a Limit of 0
answered the Limit text, where the service answers SerializationException.
shape_fault_first now reads each member on its own, beside TableName, and
each ExpressionAttributeValues value on its own.

The check also counted two kinds of member as shape faults that the
service reads. One is a string in ConsistentRead or ScanIndexForward that
the service reads as a boolean, such as "true", "T" or "0". The other is
a number in Limit. Beside Select: "NOPE", each answered
SerializationException here, where the service and main answer the
Select text. The check now skips them. A string such as "on" stays a
shape fault, as on the service. The handler's deserializer still refuses
every string in these members.

I measured the service answers on 2026-11-23, each body twice. On
e2d90f1, 7 of the 11 new unit rows fail, and 7 of the 11 new rows in
tests/test_query_value_shapes.py fail.

* fix(query): leave the check's answer beside a null member or name

When a request-time check fails, shape_fault_first deserializes each
member on its own. It reports a member of the wrong JSON type ahead of
the check, as the service does. It counted two nulls as such a member.
ScanIndexForward: null beside Select: "NOPE" answered
SerializationException here, where the service and main answer the
Select text. ExpressionAttributeNames: {"#a": null} beside an invalid
Select or ReturnConsumedCapacity did the same.

The service reads a null member as an absent one and a null name as an
empty name, which it reports after these checks. shape_fault_first now
skips a null member, with the rule present() already applies to the
parameter mix, and reads ExpressionAttributeNames without its null
names. The handler's deserializer still refuses both nulls.

I measured the service answers on 2026-11-24, each body twice. On
d7e6ff3, the 3 new unit rows fail, and the 3 new rows in
tests/test_query_value_shapes.py fail.

* fix(query): name a set fault beside a second type descriptor

For an ExpressionAttributeValues value with two type descriptors,
first_fault reads each payload and names the first fault ahead of the
more than one datatypes text. It read the numbers only. The service
also refuses an empty set and a set with a duplicate member there.
{"SS": ["a", "a"], "N": "1"} answered the more than one datatypes text
here, where the service answers "Input collection [a, a] contains
duplicates." for :z, and {"NS": ["1", "1"], "S": "x"} answers "Input
collection contains duplicates".

first_fault now takes these set faults too, on this path only. It reads
SS ahead of the numbers, so {"SS": ["a", "a"], "N": "bob"} answers the
duplicate text. It reads NS after its own numbers, so {"NS": ["1", "1"],
"N": "bob"} answers the numeric text. The SS and BS texts come from the
AttributeValue deserializer. The NS text and its check move from core's
partiql module to validation::number, so a build without the partiql
feature has them. The deserializer still reports a set with a duplicate
member and no second descriptor, as before.

I measured the service answers on 2026-11-24, each body twice. On
0e0f078, 12 of the 15 new unit rows fail, and 12 of the 15 new rows
in tests/test_query_value_shapes.py fail. The 3 rows that answer the
numeric text pass there and pin what does not change.

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

The nested refusal rows hold at e1b6f79. NS ["é"], L [N "é"] and M {k: N "é"} in ScanFilter, QueryFilter and KeyConditions answer The parameter cannot be converted to a numeric value: é on the service in us-east-1, twice each, and L [N "a1"] answers with a1; the 53 missing-table rows answer as written on the service and on SQLite and PostgreSQL servers built from this head.

With the pass rule from bfbf7e3 brought back for nested numbers only, the unit test fails at legacy_filter_tests.rs:300 and exactly the 12 new wire rows fail; applied to one container at a time it fails that container's rows. The commit changes only tests and the condition_values comment, the 418 shapes from the earlier round answer as before, the wire file passes 163 of 163 on both backends, and fmt, clippy, the 1.91.1 check and core (1190) and engine (947) tests are clean. The wasm CI failure is main's (collector*.rs), which #1482 fixes.

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

v1 Needed for the 1.0 release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Legacy QueryFilter, ScanFilter and KeyConditions: eight differences from DynamoDB

3 participants