Repository navigation
fix(query): check the numbers of KeyConditions and QueryFilter values - #1364
LeeroyHannigan wants to merge 39 commits into
Conversation
…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.
…y sentence matches the other backends
…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.
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.
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.
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
left a comment
There was a problem hiding this comment.
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)?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
ExpressionAttributeNamesorExpressionAttributeValueswith no expression come ahead of every condition value, theQueryFiltervalues too. So does aConditionalOperatorwith oneQueryFiltercondition, with none, or withXOR.- The
QueryFilteroperator (FOO) and the value count (BETWEENwith one value) come ahead of theKeyConditionsvalues.FOOwith{"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.
| .flat_map(sorted_entries) | ||
| .filter_map(|(_, condition)| condition.get("AttributeValueList")?.as_array()) | ||
| .flatten() | ||
| .filter(|value| !unreadable(value)), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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"}inQueryFilteranswers the more than one datatypes text, and{}the empty-value text.- With
SelectBADbeside the first one, the answer is theSelecttext.
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
left a comment
There was a problem hiding this comment.
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)?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| .flat_map(sorted_entries) | ||
| .filter_map(|(_, condition)| condition.get("AttributeValueList")?.as_array()) | ||
| .flatten() | ||
| .filter(|value| !unreadable(value)), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
@demohan The threads have the answers to the two conditions. On the optional point at
|
Changes since the last review
QueryFiltervalue that the service cannot read as one type now stops the check, so the deserializer reports that value after theSelectcheck. The function moves tocrates/engine/src/query_key_values/condition_values.rs. The engine testlegacy_condition_values_get_the_number_checkhas a row for each request of that table.tests/test_query_key_value_types.pyhas a row for each one that ExtendDB now answers with the service's text. Three texts that these rows use move to that file fromtests/test_query_value_shapes.py, which already imports from it.What
Query now refuses an
Nvalue that is not a number in theAttributeValueListof aKeyConditionsorQueryFiltercondition, as DynamoDB does. The answer isValidationExceptionwithThe 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 ofExpressionAttributeValues.The check runs after the number check of
ExpressionAttributeValuesand before theSelectenum. It checks theQueryFiltervalues first, then theKeyConditionsvalues. It also comes after theReturnConsumedCapacityenum and theLimitcheck, and before the key type check and the value count check ofKeyConditions. DynamoDB makes these checks ahead of the values, and the check leaves a request that fails one of them to the handler:ExpressionAttributeNamesorExpressionAttributeValueswith no expression that can use them, and aConditionalOperatoroutside its enum or without two or moreQueryFilterconditions.KeyConditionsvalues: the operator and the number of values of eachQueryFiltercondition, after the numbers of that condition.A
QueryFiltervalue that the service cannot read as one type, such as{"S": "x", "N": "1"}or{}, stops the check. The deserializer then reports it, after theSelectcheck.validate_condition_value_numbersincrates/engine/src/query_key_values/condition_values.rsreads eachAttributeValueListvalue of the request body. It uses the number rules and texts of #544 (first_fault,Fault::request_time_text). AKeyConditionsvalue that the service cannot read as one type goes to the deserializer throughunreadable, as in #544. For the checks ahead of the values, the function reusesvalidate_conditional_operator_usage, theConditionalOperatordeserializer anddesugar_filterof the handler. It repeats on the raw body the two conditions of the handler'svalidate_expression_param_usagecall, because that function reads the typed maps.refuse_first_faultnow holds the error mapping of both number checks.The open PR #507 adds the same number check for the typed values of
KeyConditions,QueryFilterandScanFilter, ascondition_valuesincrates/core/src/validation/number/operations.rs. #507 runs it in the handler, after the request-time checks of #544, which include theSelectenum. DynamoDB answers the number text ahead of theSelecttext (row K5), so this PR checks the values in the request body instead. When #507 rebases onto this change, it can keep its check forScanFilteronly.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 GSIngsionn(N). The second table haspk(S). Neither table holds an item.NUM(
v) isValidationExceptionwithThe parameter cannot be converted to a numeric value: v.KeyConditionspkEQ[{"N": "abc"}]abc)Count0{"N": ""}Count0{"N": " 5"}5)Count0pkEQ[{"N": "1"}],skBETWEEN[{"N": "1"}, {"N": "x"}]x)InternalServerErrorpkEQ[{"N": "1"}],skGT[{"N": "1e200"}]Number overflow. Attempting to store a number with magnitude larger than supported rangeCount0pkEQ[{"N": "1"}]Count0Count0IndexNamengsi,nEQ[{"N": "abc"}]abc)Count0{"N": ""}Count0pkEQ[{"N": "abc"}]abc)pkEQ[{"N": "abc"}, {"N": "1"}]abc)Query key condition must have exactly one value for EQSelectBADabc)Selectenum textReturnConsumedCapacityBADreturnConsumedCapacityenum textLimit0LimittextFilterExpressiona = :v,:v{"N": "bob"}bob)bob)QueryFilteraEQ[{"N": "bob"}]bob)Count0pkEQ[{"N": "1"}],QueryFilteraEQ[{"N": "bob"}]bob)Count0ExtendDB 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 anLEvalue or as aBETWEENbound 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:
KeyConditionspkEQ[{"N": "abc"}]abc)pkEQ[{"S": "x"}],QueryFilteraEQ[{"N": "bob"}]bob)pkEQ[{"N": "\uff11"}]ResourceNotFoundExceptionpkEQ[{"N": "abc"}],QueryFilteraEQ[{"N": "bob"}]bob)KeyConditionsaEQ[{"N": "abc"}],QueryFilterzEQ[{"N": "bob"}]bob)pkEQ[{"N": "abc", "S": "x"}]abc)pkEQ[{"S": "x"}],QueryFilteraEQ[{"N": "bob", "S": "x"}]bob)Q1 shows that the service runs the check before the table lookup, as this PR does. Q5 and Q6 show the
QueryFiltervalues ahead of theKeyConditionsvalues 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
KeyConditionspkEQ[{"N": "abc"}], KS isKeyConditionspkEQ[{"S": "x"}], and QF(v) isQueryFilteraEQ[v].{"S": "x"}),ConditionalOperatorORConditionalOperator can only be used when Filter or Expected has two or more elementsConditionalOperatorORConditionalOperator cannot be used without Filter or ExpectedExpressionAttributeValuesExpressionAttributeValues can only be specified when using expressionsExpressionAttributeNamesExpressionAttributeNames can only be specified when using expressions{"S": "x", "N": "1"})Supplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypes{})Supplied AttributeValue is empty, must contain exactly one of the supported datatypesSelectBADSelectenum textQueryFilteraFOO[{"S": "x"}]Value 'FOO' at 'queryFilter.a.member.comparisonOperator' failed to satisfy constraint: Member must satisfy enum value set: [...]Unsupported filter operator: FOOon a table that exists, as on mainQueryFilteraBETWEEN[{"N": "1"}]One or more parameter values were invalid: Invalid number of argument(s) for the BETWEEN ComparisonOperatorBETWEEN requires exactly 2 valueson a table that exists, as on mainaandb,ConditionalOperatorXORValue 'XOR' at 'conditionalOperator' failed to satisfy constraint: Member must satisfy enum value set: [AND, OR]1 validation error detected:, as on mainTableNamea1 validation error detected: Value 'a' at 'tableName' failed to satisfy constraint: Member must have length greater than or equal to 3abc){"N": "bob"}),ExpressionAttributeValues{"N": "bob"}),ConditionalOperatorOR{"N": "bob"}),ExpressionAttributeNamesExpressionAttributeValuesQueryFilteraFOO[{"N": "bob"}]bob)QueryFiltera{"S": "x", "N": "1"}andb{"N": "bob"}QueryFiltera{"N": "bob"}andb{"S": "x", "N": "1"}bob)QueryFiltera{"N": "bob"}andb{"S": "y"},XOR{"N": "bob"}),TableNameabob)aandb,ConditionalOperatorANDabc){"S": "x"})abc)On a table that does not exist, P1 to P4, P11, P12, P16 and P14 get
ResourceNotFoundExceptionhere. 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
QueryFilterconditions with a number fault each got the fault of either condition. P26 (bbbandaaa) answeredbx,ax,bxandaxin four sends, and P27 (pppandsss) answeredpxthree times andsxonce.Not in this PR
A value with two type descriptors, such as
{"N": "abc", "S": "x"}in Q7 and Q8. This PR leaves such a value to the deserializer, which answers the more than one datatypes text. The open PR fix(core): check every payload of a two descriptor value before the count #1418 reads theKeyConditionsandQueryFiltervalues with the payload checks before the descriptor count. A SQLite build of fix(core): check every payload of a two descriptor value before the count #1418's head 1546b2b answers Q7 and Q8 as DynamoDB does. With such a value inQueryFilterand a number fault inKeyConditions, DynamoDB answers the more than one datatypes text (P5), and so does this PR. A request with such a value inKeyConditionsand a number fault in another condition is not measured.The handler gives its own texts to P7, P8, P9 and P21. Query does not check the
TableNamelength (P10 and P22). The handler makes the checks of P1 to P4 after the table lookup (P14). Query looks up the table before its ConditionalOperator, QueryFilter and unused expression map checks #1554, Query and Scan put the1 validation error detected:prefix on an invalid ConditionalOperator, and DynamoDB sends the text without it #1049 and GetItem, BatchGetItem, BatchWriteItem and TransactWriteItems look up a table name shorter than 3 or longer than 255 characters, and DynamoDB refuses its length #1056 track them with these measurements. The open PR fix(expressions): validate in the service's order, with its messages #399 gives P8 the service's text.Not measured:
ScanFiltervalues of Scan (Legacy QueryFilter, ScanFilter and KeyConditions: eight differences from DynamoDB #477).ExpressionAttributeValues.Conflicts
git merge-treeshows no conflict withmainat c8e66fb. #507 conflicts with main already, incrates/core/src/expression/mod.rs,crates/engine/src/expression_helpers.rs,crates/engine/src/query.rsanddocs/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 ofvalidate_query_request_bodyincrates/engine/src/query_key_values.rsand one in the imports ofrequest_order_tests.rs. The resolution keeps theirLimitrange wording and adds this PR's clause on the numbers of theQueryFilterandKeyConditionsvalues after "every number inExpressionAttributeValues". In the imports it takes their lines and addsSELECT_BAD. On #850 and #854,query_key_values.rsno longer importsunreadable, so the resolution also addsuse 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 itsparitycorpus test: 4 passed.cargo +1.97.0 fmt --all -- --checkis clean. The two clippy commands of.github/workflows/clippy.ymlwith-D warningsandcargo +1.94.0 check --all-targetsare clean onextenddb-engine.cargo +1.97.0 clippy -p extenddb-engine --all-targets -- -W clippy::pedanticgives no warning on a line that this PR adds..github/workflows/wasm.ymlis clean on the branch.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.pyandtests/python/test_query_scan.py.python3 -m pytest --collect-only -qcollects 7332 tests intests/and 820 intests/python, with no error.legacy_condition_values_get_the_number_checkthen fails at P1, which gets the number text. Three mutants fail the same test:QueryFiltervalue is skipped instead of stopping the check, it fails at P17.QueryFilteroperator 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.rstocondition_values.rs.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, 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
KeyConditionsorQueryFilterholds anNvalue that is not a number, or a number out of range, now answers HTTP 400ValidationExceptionwith DynamoDB's text. Before, it answered HTTP 200 withCount0, or the key type, value count orSelecttext. A sort keyBETWEENbound 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.