Skip to content

fix(query): check the numbers of KeyConditions and QueryFilter values - #1364

Open
LeeroyHannigan wants to merge 39 commits into
mainfrom
fix/1252-legacy-condition-numbers
Open

LeeroyHannigan wants to merge 39 commits into
mainfrom
fix/1252-legacy-condition-numbers

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

  • 3a2808c merges main at c8e66fb, 33 PRs after the last merge, fix(core): read the latency segment clock through web_time #1482 among them. Git merged every file with no conflict, and main did not change the three files of this PR.
  • e1d1842 answers the reviews of demohan (27 November) and LJMart11 (28 November). DynamoDB makes some checks ahead of the numbers of the condition values, as the table of 3 December 2026 below shows. When a request fails one of them, the number check now leaves it to the handler, which makes these checks. A QueryFilter value that the service cannot read as one type now stops the check, so the deserializer reports that value after the Select check. The function moves to crates/engine/src/query_key_values/condition_values.rs. The engine test legacy_condition_values_get_the_number_check has a row for each request of that table. tests/test_query_key_value_types.py has a row for each one that ExtendDB now answers with the service's text. Three texts that these rows use move to that file from tests/test_query_value_shapes.py, which already imports from it.
  • In this description: What, the measurements of 3 December 2026, Not in this PR, Conflicts and Testing done.

What

Query now refuses an N value that is not a number in the AttributeValueList of a KeyConditions or QueryFilter condition, as DynamoDB does. The answer is ValidationException with The parameter cannot be converted to a numeric value: <value>, or the overflow text for a number past the range. #544 gives these texts to a value of ExpressionAttributeValues.

The check runs after the number check of ExpressionAttributeValues and before the Select enum. It checks the QueryFilter values first, then the KeyConditions values. It also comes after the ReturnConsumedCapacity enum and the Limit check, and before the key type check and the value count check of KeyConditions. DynamoDB makes these checks ahead of the values, and the check leaves a request that fails one of them to the handler:

  • Ahead of every value: ExpressionAttributeNames or ExpressionAttributeValues with no expression that can use them, and a ConditionalOperator outside its enum or without two or more QueryFilter conditions.
  • Ahead of the KeyConditions values: the operator and the number of values of each QueryFilter condition, after the numbers of that condition.

A QueryFilter value that the service cannot read as one type, such as {"S": "x", "N": "1"} or {}, stops the check. The deserializer then reports it, after the Select check.

validate_condition_value_numbers in crates/engine/src/query_key_values/condition_values.rs reads each AttributeValueList value of the request body. It uses the number rules and texts of #544 (first_fault, Fault::request_time_text). A KeyConditions value that the service cannot read as one type goes to the deserializer through unreadable, as in #544. For the checks ahead of the values, the function reuses validate_conditional_operator_usage, the ConditionalOperator deserializer and desugar_filter of the handler. It repeats on the raw body the two conditions of the handler's validate_expression_param_usage call, because that function reads the typed maps. refuse_first_fault now holds the error mapping of both number checks.

The open PR #507 adds the same number check for the typed values of KeyConditions, QueryFilter and ScanFilter, as condition_values in crates/core/src/validation/number/operations.rs. #507 runs it in the handler, after the request-time checks of #544, which include the Select enum. DynamoDB answers the number text ahead of the Select text (row K5), so this PR checks the values in the request body instead. When #507 rebases onto this change, it can keep its check for ScanFilter only.

The base of this PR is main. #544 merged into main on 25 November.

Why

Fixes #1252
Fixes #1363

These are DynamoDB's answers, measured in us-east-1 on 22 November 2026. Each request went out twice and got the same answer both times. The first table has pk (N) as its partition key, sk (N) as its sort key and a KEYS_ONLY GSI ngsi on n (N). The second table has pk (S). Neither table holds an item.

NUM(v) is ValidationException with The parameter cannot be converted to a numeric value: v.

Request DynamoDB ExtendDB on #544
KeyConditions pk EQ [{"N": "abc"}] NUM(abc) HTTP 200, Count 0
the same with {"N": ""} NUM(), with a colon and a space at the end HTTP 200, Count 0
the same with {"N": " 5"} NUM( 5) HTTP 200, Count 0
pk EQ [{"N": "1"}], sk BETWEEN [{"N": "1"}, {"N": "x"}] NUM(x) HTTP 500 InternalServerError
pk EQ [{"N": "1"}], sk GT [{"N": "1e200"}] Number overflow. Attempting to store a number with magnitude larger than supported range HTTP 200, Count 0
pk EQ [{"N": "1"}] HTTP 200, Count 0 HTTP 200, Count 0
IndexName ngsi, n EQ [{"N": "abc"}] NUM(abc) HTTP 200, Count 0
the same with {"N": ""} NUM() HTTP 200, Count 0
the second table, pk EQ [{"N": "abc"}] NUM(abc) the key type text
pk EQ [{"N": "abc"}, {"N": "1"}] NUM(abc) Query key condition must have exactly one value for EQ
the first row with Select BAD NUM(abc) the Select enum text
the first row with ReturnConsumedCapacity BAD the returnConsumedCapacity enum text the same text
the first row with Limit 0 the Limit text the same text
the first row with FilterExpression a = :v, :v {"N": "bob"} NUM(bob) NUM(bob)
the first row with QueryFilter a EQ [{"N": "bob"}] NUM(bob) HTTP 200, Count 0
pk EQ [{"N": "1"}], QueryFilter a EQ [{"N": "bob"}] NUM(bob) HTTP 200, Count 0

ExtendDB on #544 gives DynamoDB's answer to 4 of the 16 rows. This PR gives it to all 16. The HTTP 500 comes from the SQLite sort key encoder (invalid numeric sort key). This PR refuses that request before the storage layer. #544 also answers HTTP 500 to {"N": "abc"} as an LE value or as a BETWEEN bound of the sort key, which no row measures on DynamoDB. This PR answers NUM(abc) there.

The rows below are DynamoDB's answers of 25 November 2026, measured in the same way, on a table that does not exist:

Row Request DynamoDB This PR
Q1 KeyConditions pk EQ [{"N": "abc"}] NUM(abc) the same
Q2 pk EQ [{"S": "x"}], QueryFilter a EQ [{"N": "bob"}] NUM(bob) the same
Q3 pk EQ [{"N": "\uff11"}] ResourceNotFoundException the same
Q5 pk EQ [{"N": "abc"}], QueryFilter a EQ [{"N": "bob"}] NUM(bob) the same
Q6 KeyConditions a EQ [{"N": "abc"}], QueryFilter z EQ [{"N": "bob"}] NUM(bob) the same
Q7 pk EQ [{"N": "abc", "S": "x"}] NUM(abc) the more than one datatypes text
Q8 pk EQ [{"S": "x"}], QueryFilter a EQ [{"N": "bob", "S": "x"}] NUM(bob) the more than one datatypes text

Q1 shows that the service runs the check before the table lookup, as this PR does. Q5 and Q6 show the QueryFilter values ahead of the KeyConditions values when the attribute names are in the other order.

The rows below are DynamoDB's answers of 3 December 2026, measured in the same way, on a table that does not exist. KC is KeyConditions pk EQ [{"N": "abc"}], KS is KeyConditions pk EQ [{"S": "x"}], and QF(v) is QueryFilter a EQ [v].

Row Request DynamoDB This PR
P1 KC, QF({"S": "x"}), ConditionalOperator OR ConditionalOperator can only be used when Filter or Expected has two or more elements the same on a table that exists
P2 KC, ConditionalOperator OR ConditionalOperator cannot be used without Filter or Expected the same on a table that exists
P3 KC, ExpressionAttributeValues ExpressionAttributeValues can only be specified when using expressions the same on a table that exists
P4 KC, ExpressionAttributeNames ExpressionAttributeNames can only be specified when using expressions the same on a table that exists
P5 KC, QF({"S": "x", "N": "1"}) Supplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypes the same
P6 KC, QF({}) Supplied AttributeValue is empty, must contain exactly one of the supported datatypes the same
P13 P5 with Select BAD the Select enum text the same
P7 KC, QueryFilter a FOO [{"S": "x"}] Value 'FOO' at 'queryFilter.a.member.comparisonOperator' failed to satisfy constraint: Member must satisfy enum value set: [...] Unsupported filter operator: FOO on a table that exists, as on main
P8 KC, QueryFilter a BETWEEN [{"N": "1"}] One or more parameter values were invalid: Invalid number of argument(s) for the BETWEEN ComparisonOperator BETWEEN requires exactly 2 values on a table that exists, as on main
P9 KC, QF a and b, ConditionalOperator XOR Value 'XOR' at 'conditionalOperator' failed to satisfy constraint: Member must satisfy enum value set: [AND, OR] the same clause after 1 validation error detected: , as on main
P10 KC with TableName a 1 validation error detected: Value 'a' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3 NUM(abc)
P11 KS, QF({"N": "bob"}), ExpressionAttributeValues the P3 text the same on a table that exists
P12 KS, QF({"N": "bob"}), ConditionalOperator OR the P1 text the same on a table that exists
P16 KS, QF({"N": "bob"}), ExpressionAttributeNames the P4 text the same on a table that exists
P14 KS, ExpressionAttributeValues the P3 text the P3 text on a table that exists
P15 KS, QueryFilter a FOO [{"N": "bob"}] NUM(bob) the same
P17 KS, QueryFilter a {"S": "x", "N": "1"} and b {"N": "bob"} the P5 text the same
P18 KS, QueryFilter a {"N": "bob"} and b {"S": "x", "N": "1"} NUM(bob) the same
P21 KS, QueryFilter a {"N": "bob"} and b {"S": "y"}, XOR the P9 text the P9 answer
P22 KS, QF({"N": "bob"}), TableName a the P10 text NUM(bob)
P23 KC, QF a and b, ConditionalOperator AND NUM(abc) the same
P25 KC, QF({"S": "x"}) NUM(abc) the same

On a table that does not exist, P1 to P4, P11, P12, P16 and P14 get ResourceNotFoundException here. The handler makes these checks after the table lookup. By its code, main answers them the same way, because it has no number check of these values. #1554 tracks P1 to P4, P7, P8, P11, P12, P14 and P16. #1049 tracks P9 and P21, and #1056 tracks P10 and P22.

Two QueryFilter conditions with a number fault each got the fault of either condition. P26 (bbb and aaa) answered bx, ax, bx and ax in four sends, and P27 (ppp and sss) answered px three times and sx once.

Not in this PR

Not measured:

Conflicts

git merge-tree shows no conflict with main at c8e66fb. #507 conflicts with main already, in crates/core/src/expression/mod.rs, crates/engine/src/expression_helpers.rs, crates/engine/src/query.rs and docs/differences-from-dynamodb.md, and this PR adds no conflict to it.

#854 and #850 conflict with main already, in the files of crates/engine/src/query_key_values/ among others. Against this PR, each gets a hunk in the doc comment of validate_query_request_body in crates/engine/src/query_key_values.rs and one in the imports of request_order_tests.rs. The resolution keeps their Limit range wording and adds this PR's clause on the numbers of the QueryFilter and KeyConditions values after "every number in ExpressionAttributeValues". In the imports it takes their lines and adds SELECT_BAD. On #850 and #854, query_key_values.rs no longer imports unreadable, so the resolution also adds use unreadable::unreadable;.

#1418 merges with this PR without a conflict.

Testing done

The cargo runs are on f175471156. It differs from e1d1842 only in the two Python test files that e1d1842 changes.

  • cargo test -p extenddb-engine --lib: 982 passed.
  • cargo test -p extenddb-wasm-adapter, with its parity corpus test: 4 passed.
  • cargo +1.97.0 fmt --all -- --check is clean. The two clippy commands of .github/workflows/clippy.yml with -D warnings and cargo +1.94.0 check --all-targets are clean on extenddb-engine.
  • cargo +1.97.0 clippy -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 on the branch.
  • Against a SQLite server built from e1d1842, seven Python files passed 557 tests: tests/test_query_key_value_types.py, tests/test_query_value_shapes.py, tests/test_conditional_operator.py, tests/test_expression_param_usage.py, tests/test_query_leading_keys_values.py, tests/test_query_scan.py and tests/python/test_query_scan.py.
  • python3 -m pytest --collect-only -q collects 7332 tests in tests/ and 820 in tests/python, with no error.
  • The control puts back the production code of 3a2808c. legacy_condition_values_get_the_number_check then fails at P1, which gets the number text. Three mutants fail the same test:
    • Without the checks ahead of the values, it fails at P1.
    • When an unreadable QueryFilter value is skipped instead of stopping the check, it fails at P17.
    • Without the QueryFilter operator and count check, it fails at P7.

Production over main is +120 -8 lines, comments included, and the tests are +224 -15. e1d1842 adds 104 and removes 20 production lines, 20 of them moved from query_key_values.rs to condition_values.rs.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a

Breaking changes

  • A Query whose KeyConditions or QueryFilter holds an N value that is not a number, or a number out of range, now answers HTTP 400 ValidationException with DynamoDB's text. Before, it answered HTTP 200 with Count 0, or the key type, value count or Select text. A sort key BETWEEN bound got HTTP 500. A request whose numbers are valid gets the same answer as before. So does a request that also fails a check that DynamoDB makes ahead of the numbers.

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 23 commits October 24, 2026 23:36
…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 #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.
… 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.
…ort 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.
…ks, 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.
Conflict in crates/server/src/request_helpers.rs (authorize_request): main
moves the ARN shape checks and the GetRecords iterator decode ahead of the
dev-mode return. The resolution keeps the main version and puts the Query
request checks of this branch after the tag ARN shape check and before
validate_operation_arns. Thus the Query checks also run in dev mode.
Main changes resolve_multipart to take the HASH and the RANGE attribute
names (#429). The multi-attribute HASH test now gives r as the RANGE
attribute, as its attribute definitions do.
…l 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.
…rder 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).
…rder

- 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.
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.
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.
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.
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.
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.
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.
Query passes an N value of legacy KeyConditions to the storage layer
without the number check. On SQLite, {"N": "abc"} as the partition key
value reads the text abc and answers 200 with Count 0. {"N": "x"} as a
BETWEEN bound on an N sort key answers HTTP 500, as the backend cannot
encode the key. The values of QueryFilter get no number check either.

Amazon DynamoDB refuses these values with ValidationException
(us-east-1, 22 Nov 2026, each request twice):

- KeyConditions pk EQ {"N": "abc"}: The parameter cannot be converted
  to a numeric value: abc
- pk EQ {"N": ""}: the same text, ending in the colon and a space
- pk EQ {"N": " 5"}: the same text with " 5" after the colon
- sk BETWEEN {"N": "1"} and {"N": "x"}: the text for x
- sk GT {"N": "1e200"}: Number overflow. Attempting to store a number
  with magnitude larger than supported range
- GSI key n EQ {"N": "abc"} or {"N": ""}: the texts above
- QueryFilter a EQ {"N": "bob"}: the text for bob
- pk EQ {"N": "1"}: 200 with Count 0

DynamoDB reports this fault after an invalid ReturnConsumedCapacity, a
Limit of 0 and such a number in ExpressionAttributeValues or
QueryFilter. It reports the fault ahead of an invalid Select, a key
value of the wrong type and two values for EQ.

query_request_checks now gives each AttributeValueList value of
QueryFilter and then of KeyConditions the number check of
ExpressionAttributeValues, ahead of the Select enum. The check reuses
first_fault and its texts. It leaves a value that DynamoDB cannot read
as one type to the deserializer. With several faults, it reports the
first in attribute name order and then in list order. No measured
request has two.

Tested with the 16 measured requests as one table in the engine tests
and as rows of tests/test_query_key_value_types.py.

Fixes #1252.
Fixes #1363.
@LeeroyHannigan
LeeroyHannigan marked this pull request as ready for review November 23, 2026 11:28
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.
TestShapeFaultsAreReportedFirst asserts the error type only, because the
SerializationException texts of the service differ from those of
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/differences-from-dynamodb.md gets a Query section. Its rows give the
order of the cross-account refusal and the request checks (#974), and N
values written with Unicode decimal digits (#565). A third row gives the
wrapper that the service adds beside a Limit above 2147483647 (#976).
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.
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.
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.
The base finds a shape fault in any member and value, and names a set
fault beside a second type descriptor. For the set fault, first_fault
takes a third parameter, sets. The check of a value with several type
descriptors passes true, and the number check of ExpressionAttributeValues
passes false.

The one conflict is in crates/engine/src/query_key_values.rs. This branch
moves the first_fault call of that number check into refuse_first_fault,
which the KeyConditions and QueryFilter check calls too. The merge keeps
this branch's refuse_first_fault and passes false, as the base does for
that number check. So a set fault in a condition value stays with the
deserializer, as before.
The doc comment of validate_condition_value_numbers said that no measured
request has two faults. Rows K7 and K11 have two faults, one in
KeyConditions and one in QueryFilter or ExpressionAttributeValues, and
they set the order that the check uses. The comment now says that no
measured request has two faults in one field.
Base automatically changed from fix/query-key-value-types to main November 25, 2026 10:57
Main is at 14ade59. This branch last had main at 018715e, through
fix/query-key-value-types. Since then, these eleven commits merged
into main: #1280, #1009, #596, #1173, #398, #428, #544, #567, #584,
#588 and #864.

#544 is the squash of fix/query-key-value-types, which was the base
branch of this PR. This branch already holds the last head of that
branch, 31c5f3d. Main has the same version of each conflicted file as
31c5f3d. So each conflict hunk has the lines of #544 on one side.
The other side has the change of this branch to the same lines. The
merge keeps the version of this branch in each file:

- crates/engine/src/query_key_values.rs: the dates and the order in
  the module and function doc comments, the call of
  validate_condition_value_numbers, and the two functions
  validate_condition_value_numbers and refuse_first_fault.
- crates/engine/src/query_key_values/request_order_tests.rs: the
  import of Value and the test
  legacy_condition_values_get_the_number_check.
- tests/test_query_key_value_types.py: the dates in the docstring, the
  nn_table fixture and the helpers eq, N1, KC_ABC and QF_BOB. The merge
  also keeps the rows k1 to k16, and nn_table in the tables fixture and
  the control test.

Git merged crates/engine/src/lib.rs with no conflict. This branch
changes that file only through the commits of #544, so the merged file
is the file of main.

@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 number check is right at ab97c84, and its place against the other Query checks needs to move. Of 145 request shapes sent to us-east-1, this head matches the service on 118 and main on 31, 94 of them fixed here: unparsable values, 38 and 39 digits, overflow, underflow and non-ASCII digits answer as the service does in KeyConditions, QueryFilter, a GSI and the sort key BETWEEN bound, and SQLite and PostgreSQL answer alike on all 173 shapes. No request carrying only valid numbers changed from main. Removing the call, swapping the order, or moving it before Limit or after Select each fails a row, and tests/test_query_key_value_types.py passes 229 on the service and both backends and fails 12 on main. The branch merges into current main and builds with sqlx 0.9.1, and fmt, clippy, the 1.94.0 check and the engine and core tests are clean.

I will approve once the number check runs after the checks the service makes first, as listed below, and an unreadable QueryFilter value still answers its own fault.

tests/test_query_key_value_types.py:1

Optional. The rows cover EQ, BETWEEN and GT and one overflow; underflow, the 38-digit limit, non-ASCII digits, nested L, M and NS values and the other operators all answer as the service does here and would be short rows. The body says two faults in one field are named in attribute-name order; the service has no fixed order there (bbb/aaa 2 and 2, ppp/sss 3 and 1).

if let Some(values) = values {
validate_expression_attribute_value_numbers(values)?;
}
validate_condition_value_numbers(body)?;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This now runs ahead of four checks the service makes first, and main gave the service's text for all four: one QueryFilter condition with ConditionalOperator OR, ConditionalOperator with no QueryFilter, ExpressionAttributeValues without expressions, and ExpressionAttributeNames without expressions, four samples each, now answer The parameter cannot be converted to a numeric value: abc. The service also finishes each QueryFilter condition, its values, the operator and the argument count, before it reads the KeyConditions values, and checks the TableName length before both: QueryFilter operator FOO, BETWEEN with one value, ConditionalOperator XOR and TableName a answer the number text here, where main was already wrong.

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.

e1d1842 puts the number check behind the checks you list. When a request fails one of them, the check now leaves it to the handler (crates/engine/src/query_key_values/condition_values.rs). I sent each case to us-east-1 on 3 Dec, twice, on a table that does not exist:

  • ExpressionAttributeNames or ExpressionAttributeValues with no expression come ahead of every condition value, the QueryFilter values too. So does a ConditionalOperator with one QueryFilter condition, with none, or with XOR.
  • The QueryFilter operator (FOO) and the value count (BETWEEN with one value) come ahead of the KeyConditions values. FOO with {"N": "bob"} in the same condition answers the number text, so the check reads the values of a condition before its operator.

On a table that exists, your four requests now get the service's text from the handler, as on main. FOO, the one-value BETWEEN and XOR get the handler's own texts, as on main. TableName a still answers the number text. Query checks no table name length, so a valid request on a answers ResourceNotFoundException. #1554 tracks the FOO text and the place of these checks after the table lookup, with the measurements. #1049 tracks the XOR text, and #1056 tracks the length check on Query. The open PR #399 gives the one-value BETWEEN the service's text.

The engine test legacy_condition_values_get_the_number_check has a row for each of these requests. tests/test_query_key_value_types.py has a row for each one that ExtendDB now answers with the service's text.

Comment thread crates/engine/src/query_key_values.rs Outdated
.flat_map(sorted_entries)
.filter_map(|(_, condition)| condition.get("AttributeValueList")?.as_array())
.flatten()
.filter(|value| !unreadable(value)),

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.

Skipping a value that cannot be read lets a bad KeyConditions number win over it: QueryFilter {"S":"x","N":"1"} answers the two-datatypes text on main and on the service and {} the empty-value text, and both answer the number text here. With such a value the service reports the Select and Limit faults first, as it does for ExpressionAttributeValues, so dropping the filter alone would not match either. No test holds this line: removing it leaves all 34 query_key_values tests passing.

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.

e1d1842 stops the number check at a QueryFilter value that the service cannot read as one type, so the deserializer reports that value. I sent these to us-east-1 on 3 Dec, twice each, on a table that does not exist, with KeyConditions {"N": "abc"}:

  • {"S": "x", "N": "1"} in QueryFilter answers the more than one datatypes text, and {} the empty-value text.
  • With Select BAD beside the first one, the answer is the Select text.

The Limit and Select checks run ahead of the number check, so they still come first. A number fault in a QueryFilter condition that the check reads before the unreadable value still answers first. a {"N": "bob"} with b {"S": "x", "N": "1"} answered the number text, and the two the other way round the datatypes text.

Rows P5, P6, P13, P17 and P18 of the engine test hold this line. With the stop removed, the test fails at P17. Rows p5, p6 and p13 of tests/test_query_key_value_types.py send the first three.

@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 ab97c84. Engine query_key_values tests passed (34) under 1.91.1; request-order probes on the new number check found two ordering gaps.

2 findings are left inline.

if let Some(values) = values {
validate_expression_attribute_value_numbers(values)?;
}
validate_condition_value_numbers(body)?;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Move validate_condition_value_numbers after the checks the service makes first: QueryFilter with ConditionalOperator OR and one condition, ConditionalOperator without QueryFilter, ExpressionAttributeValues or ExpressionAttributeNames without expressions. Calling validate_query_request_body on a KeyConditions {"N":"abc"} plus each of those, all 4 answered The parameter cannot be converted to a numeric value: abc. A row per case in request_order_tests.rs would close 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.

e1d1842 moves the number check behind those four checks. A request that fails one of them is now left to the handler. On a table that exists, the handler gives the service's text, as on main. legacy_condition_values_get_the_number_check in request_order_tests.rs has a row for each of the four (P1 to P4). It also has rows for the same checks beside a QueryFilter number (P11, P12 and P16), which the service also answers with the check's text. I measured all seven in us-east-1 on 3 Dec, twice each. Rows p1 to p4, p11, p12 and p16 of tests/test_query_key_value_types.py send them to the server.

Comment thread crates/engine/src/query_key_values.rs Outdated
.flat_map(sorted_entries)
.filter_map(|(_, condition)| condition.get("AttributeValueList")?.as_array())
.flatten()
.filter(|value| !unreadable(value)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

A QueryFilter value {"S":"x","N":"1"} or {} beside a bad KeyConditions number answers the number text here, where main gives the two-datatypes or empty-value text. Both probes (2 of 2) on this head returned the number text. Report the unreadable value's own fault first for QueryFilter, and add a request_order_tests row for each.

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.

e1d1842 stops the number check at a QueryFilter value that the service cannot read as one type. {"S": "x", "N": "1"} and {} beside a bad KeyConditions number now get the deserializer's datatypes and empty-value texts, as on main. The service gave the same two texts in us-east-1 on 3 Dec, twice each. request_order_tests.rs has rows P5, P6 and P13 (the last with an invalid Select, which the service reports first), and tests/test_query_key_value_types.py has rows p5, p6 and p13.

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

Git merged every file with no conflict. Main did not change the three
files of this PR: crates/engine/src/query_key_values.rs,
crates/engine/src/query_key_values/request_order_tests.rs and
tests/test_query_key_value_types.py. #481 changed
crates/engine/src/query.rs, which this branch does not change.
…makes first

The number check of the QueryFilter and KeyConditions values answered
ahead of checks that DynamoDB makes first. For four of them, main gave
the service's text. These are the service's answers, measured in
us-east-1 on 3 Dec 2026 on a table that does not exist, each request
twice:

- ExpressionAttributeNames or ExpressionAttributeValues with no
  expression, and a ConditionalOperator outside its enum or without two
  or more QueryFilter conditions, come ahead of every condition value.
- The operator and the number of values of a QueryFilter condition come
  ahead of the KeyConditions values, after the numbers of that condition.
- A QueryFilter value with two type descriptors, or with none, answers
  its own text ahead of the values after it. The Select check comes
  first.

The check now leaves such a request to the handler, which makes these
checks after the table lookup. For the operator, the number of values and
the ConditionalOperator enum, the handler gives its own texts, as on main.

With number faults in two QueryFilter conditions, the service named
either one (each of two requests sent four times). The doc comment now
says so.

validate_condition_value_numbers moves to
crates/engine/src/query_key_values/condition_values.rs. The engine order
test gets a row for each of these requests. tests/test_query_key_value_types.py
gets a row for each one that ExtendDB now answers with the service's text.
Three texts that these rows use move there from
tests/test_query_value_shapes.py, which already imports from that file,
so the two files do not import each other.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@demohan The threads have the answers to the two conditions. On the optional point at tests/test_query_key_value_types.py:1:

  • The rows stay as they are. The check reads each value with first_fault of fix(query): check Query values against the key schema and the number rules #544. The rows of fix(query): check Query values against the key schema and the number rules #544 test that function through ExpressionAttributeValues: the 38-digit limit, the decimal digits outside ASCII and the L, M and NS values. Every operator gives its values to the same function.
  • The service has no fixed order there. I sent two QueryFilter conditions with a number fault each to us-east-1 on 3 Dec, four times per pair. bbb and aaa answered bx, ax, bx and ax. ppp and sss answered px three times and sx once. The doc comment of validate_condition_value_numbers now says that the service does not always name the same one. The PR body no longer gives an order for two faults in one field.

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

3 participants