Repository navigation
fix(core): refuse a second condition on a key in KeyConditionExpression - #484
LeeroyHannigan wants to merge 34 commits into
Conversation
…e key A key condition that named the same key attribute twice was served. For `pk = :a AND pk = :b` the parser took the first equality as the partition key condition and the second as the sort key condition, so on a table with pk HASH and sk RANGE the request returned the items in partition `:a` whose sort key equalled `:b`. The same hole accepted two conditions on the sort key, including BETWEEN or begins_with paired with another sort key condition. DynamoDB rejects all of these with "Invalid KeyConditionExpression: KeyConditionExpressions must only contain one condition per key" (measured 2026-10-24, us-east-1). It resolves every `#name` and `:value` reference before it looks for the duplicate, so an undefined name or value is reported first, and it reports the duplicate ahead of the key value type check and the unused-value check (measured 2026-10-31). parse_key_condition_with_maps takes the request's expression attribute names and values. After the parser's own checks, and before any clause is classified, it refuses two conditions on one key attribute, written with plain names or through `#name` references. When there is a duplicate it reports an undefined `#name` and then an undefined `:value` first. A key condition without a duplicate takes the same path as before. The engine's Query handler parses through it, and the server's LeadingKeys extraction runs the same check through key_condition_clause_operands, so a duplicate leaves dynamodb:LeadingKeys absent whichever way it is written. Fixes #430
1632b19 to
4a2d382
Compare
pdf-amzn
left a comment
There was a problem hiding this comment.
This PR seems to have become more convoluted due to how it interacts with 479. It may just be simpler to combine this and 479 into one change, I think it's going to be easier to reduce duplication overall in the result.
AI generated:
I reviewed this together with #479, since the two overlap. I tested main (cbc3680) merged with both PRs on PostgreSQL: the full pytest suite shows no regressions against main, and the new wire file passes (30/30). The new wire files also pass against DynamoDB (30/30 and 83/83).
Size. +962/-61 is mostly tests. Net against the merge base: 75 lines of production code, 58 of comments, 764 of tests (420 Rust, 344 Python). The fix itself is reject_duplicate_key_attrs plus the wiring in the two callers. Most of the remaining weight is the same duplicate-shape and check-order rows asserted at three layers: core unit tests, key_condition_duplicate_check_order_matches_the_service in expression_helpers.rs, and the Python TestOneConditionPerKey / TestDuplicateCheckOrder.
Should-fix: undefined references are checked only when there is a duplicate. reject_duplicate_key_attrs (crates/core/src/expression/key_condition.rs:485) reports an undefined #name, then an undefined :value, but only after it has found a duplicate (:507). Without one, an undefined #name is caught later and only for the clauses the classifier resolves, by resolve_path_attr (:537, called at :220 and :234 through resolve_key_schema_with). An undefined :value isn't checked in core or the engine at all: check_key_value_type skips it (crates/engine/src/query.rs:632), and the first refusal is maps.resolve_value in each backend's query builder (e.g. storage-sqlite/src/data/query.rs:46), without the Invalid KeyConditionExpression: prefix. That is the third difference listed in this PR's description. The two message strings are also written out again here; they already exist at :547 and in resolve_value_for (resolver.rs:83). Check every key condition's references once, first, in parse_key_condition_with_maps: all names, then all values, with the prefix. #479's KeyCondition::validate_references (references.rs:25) is that check. Then reject_duplicate_key_attrs only has to detect the duplicate. That would also fix the missing prefix, keep undefined values from reaching storage, and report an undefined #name ahead of "missed key schema element" (#712). One service row is needed before doing it: a no-duplicate key condition with an undefined reference plus an unused value, to confirm the order between those two checks.
Should-fix: #429's classifier still has its own duplicate check, and it can no longer fire in production. resolve_multipart_with (crates/core/src/expression/key_condition.rs:244-259) refuses one condition per key with an inline copy of the message. Every production caller now reaches it through resolve_key_schema_with after parse_key_condition_with_maps has already run reject_duplicate_key_attrs; the only remaining callers of bare parse_key_condition are tests. Either remove that branch, or keep it as a guard for the map-less parse_key_condition path with a comment saying so and point it at ONE_CONDITION_PER_KEY_ERR (:469).
Nit-or-follow-up: parse_key_condition is still pub and re-exported from expression/mod.rs, but only tests call it. Drop the re-export, or document it as the deliberately map-less entry that skips the duplicate check.
Nit-or-follow-up: on the LeadingKeys equality path the duplicate check runs twice: key_condition_clause_operands runs reject_duplicate_key_attrs, then equality_pk_value parses again with parse_key_condition_with_maps. Harmless; one shared parse would do it once.
Nit-or-follow-up: key_condition_duplicate_check_order_matches_the_service repeats 8 order rows the core unit tests and the Python file already cover. Its unique value is showing that parse_key_condition_expr passes the maps through and applies the prefix; two rows (one duplicate, one undefined name) show that. That saves about 70 lines.
Nit-or-follow-up: raw_clause_values (key_condition.rs:767) builds a Vec<&Expr> per clause; it's only on the error path, but an iterator would avoid the allocation.
Overlap with #479. #479 adds refuse_two_conditions_on_one_attribute (no_hash_equality.rs:219), which refuses the same message but only for two non-equality clauses, later, in the engine. This PR's parse-time check covers every schema and every operator, so it should own the refusal. Whichever of the two merges second should drop #479's copy; I've said the same on #479.
The FGAC change (a duplicate now leaves dynamodb:LeadingKeys absent, so some principals get ValidationException instead of AccessDeniedException) looks fine to me: the engine refuses every duplicate, so no item is read either way. Keep the "not measured" note in leading_keys.rs.
demohan
left a comment
There was a problem hiding this comment.
Measured on us-east-1, two samples per request. The duplicate refusal is correct on every base table, GSI, LSI, multi-attribute GSI and hash-only shape tried, and the wire files pass on SQLite, PostgreSQL, MongoDB and Cassandra. Four items remain: the refusal now comes ahead of FilterExpression errors that main reported correctly; it comes after the table, index, ConsistentRead and Select checks, which the service runs later; undefined references follow text order on the service; and the LeadingKeys binding for a duplicate needs a measurement before it changes. Small items: the substring assertion, and tests for the measured non-key and hash-only rows.
| // before the clauses are classified, which is where the service | ||
| // reports it (measured 2026-10-31). | ||
| let parsed = | ||
| crate::expression_helpers::parse_key_condition_expr(kce_str, &maps, &ctx.limits)?; |
There was a problem hiding this comment.
The duplicate is now refused before the FilterExpression is parsed and checked. The service reports the filter first. With KeyConditionExpression pk = :a AND pk = :b (both defined) and FilterExpression #q = :a (#q undefined), DynamoDB answers Invalid FilterExpression: An expression attribute name used in the document path is not defined; attribute name: #q (us-east-1, two samples). This branch answers KeyConditionExpressions must only contain one condition per key; main answered the filter error. The same holds for foo = :zz with :zz undefined, begins_with(foo, :n) with :n a number, name = :c (reserved word) and the filter syntax errors zz = = :c and foo = :a OR. The projection, Select, start key, unused value and key type checks come after the duplicate on the service, as here.
There was a problem hiding this comment.
Fixed in 5ea180d, which checks every FilterExpression fault ahead of every key condition fault, and your 12 Nov review measured that order. With e3e1da1, authorization runs the same checks in the same order for a key condition with a duplicate. So a principal fenced by dynamodb:LeadingKeys also gets the #q filter error, as all 7 principals did on the service on 19 Nov.
| // before the clauses are classified, which is where the service | ||
| // reports it (measured 2026-10-31). | ||
| let parsed = | ||
| crate::expression_helpers::parse_key_condition_expr(kce_str, &maps, &ctx.limits)?; |
There was a problem hiding this comment.
DynamoDB reports the duplicate ahead of the table and index lookups. pk = :a AND pk = :b against a table that does not exist answers Invalid KeyConditionExpression: KeyConditionExpressions must only contain one condition per key, not ResourceNotFoundException. It answers the duplicate too with IndexName nope, with ConsistentRead true on a GSI, with Select BOGUS, and with Select ALL_ATTRIBUTES on a KEYS_ONLY GSI. Two samples each, us-east-1. This branch answers the other error on all five. A refusal after the expression grammar, reserved word and reference checks of both expressions, and before anything that reads the table, matches every case measured here.
There was a problem hiding this comment.
Fixed in 822c472 and 5ea180d: the duplicate comes ahead of the table, index, ConsistentRead and Select checks, and b13ec53 puts Limit first. e3e1da1 keeps that order for every principal. Authorization now refuses a duplicate with the same checks before the IAM decision, and those checks read nothing from the table.
There was a problem hiding this comment.
The duplicate still answers ahead of the table, index, ConsistentRead and Select checks (B1 to B5). 5ea180d had also moved the key condition's shape checks ahead of the table, which the service does not do. On 23 Nov, on a table that does not exist, pk > :a and pk > :a AND sk > :b answered ResourceNotFoundException, as on main. In 19bb1dd the shape checks run after the table checks again, where main runs them, and the wire tests send both requests (R10, R11).
| if !duplicated { | ||
| return Ok(()); | ||
| } | ||
| for clause in clauses { |
There was a problem hiding this comment.
The service names the first undefined reference in the order the expression is written, whether it is a #name or a :value. A single reference check run first would need to walk the clauses in that order, not all names and then all values. Without a duplicate the service does the same: pk = :q AND #u = :c with no maps answers :q, and sk = :b AND pk = :a with no values answers :b. An undefined reference is reported before an unused value or name: pk = :a AND sk = :missing with :a and an unused :extra answers the :missing text (two samples each). pk = :a AND pk = :b AND #u = :c with no ExpressionAttributeNames and no ExpressionAttributeValues answers Invalid KeyConditionExpression: An expression attribute value used in expression is not defined; attribute value: :a (two samples). This loop reports #u because it checks every name before any value. pk = :q AND pk = :b AND #u = :c with :b and :c defined answers :q on the service and #u here.
There was a problem hiding this comment.
Fixed in 8b49672. One reference check walks the tokens in written order, names and values alike, before the duplicate check. Your 12 Nov review measured the reference order as the service's.
| &undefined("missing"), | ||
| "pk = :a AND pk = :missing", | ||
| ); | ||
| let tokens = tokenize("pk = :a AND pk = :b AND #u = :c").unwrap(); |
There was a problem hiding this comment.
This case expects #u; the service answers :a for this request (see the comment on line 510). The order is measurable: #u = :a AND #u = :b with no maps answers #u, and pk = :b AND pk = :a with no values answers :b.
There was a problem hiding this comment.
Fixed in 8b49672. first_undefined_reference_in_text_order_is_reported expects :a for this request with no maps. It also expects #u for #u = :a AND #u = :b and :b for pk = :b AND pk = :a.
| ) -> Result<(), DynamoDbError> { | ||
| let mut seen: Vec<&str> = Vec::with_capacity(clauses.len()); | ||
| let mut duplicated = false; | ||
| for clause in clauses { |
There was a problem hiding this comment.
Two more shapes where the service reports something else before the duplicate. pk = :a AND pk <> :b and pk = :a AND contains(pk, :b) answer the duplicate on the service and an operator error here. pk = :a AND begins_with(sk, :n) AND sk = :b with :n a number answers Invalid KeyConditionExpression: Incorrect operand type for operator or function; operator or function: begins_with, operand type: N on the service and the duplicate here.
There was a problem hiding this comment.
Fixed in 8b49672. The parse refuses <> and contains after the duplicate check, and it checks the begins_with operand type before it. Your 12 Nov review measured the three shapes as the service answers them.
| // a second condition on one key attribute, written with plain names | ||
| // or through a `#name` reference, is refused here with the check the | ||
| // engine runs, so it leaves the key absent whatever its operators. | ||
| let pk_clauses: Vec<_> = key_condition_clause_operands(&tokens, &names, &values) |
There was a problem hiding this comment.
This leaves dynamodb:LeadingKeys absent for every duplicate, where main bound the equality's value. For pk = :own AND sk = :b AND sk = :c, a principal fenced to own by ForAnyValue:StringEquals now gets AccessDeniedException instead of ValidationException, and one fenced away by ForAllValues:StringEquals without a Null guard gets ValidationException instead of AccessDeniedException. The service binds the operand and authorizes first for pk > :v (the note below). Which value it binds for a duplicate needs a measurement with a restricted principal before the binding changes.
There was a problem hiding this comment.
cc8d192 put main's binding back. With e3e1da1, authorization refuses a key condition with a duplicate before the IAM decision, so it binds no dynamodb:LeadingKeys value for one. On 19 Nov your 9 shapes answered the one-condition-per-key message to the table owner and to 6 roles. Two of those roles had no Allow for Query or a Deny on it.
| # -- An equality on the partition key decides the key ------------------ | ||
| # -- A second clause on the partition key binds nothing ---------------- | ||
|
|
||
| def test_unreadable_partition_equality_does_not_bind_another_clause(self, table): |
There was a problem hiding this comment.
Both policies here expect AccessDeniedException whether dynamodb:LeadingKeys is absent or bound to :u, so the test passes on either binding. A case where the readable value is the fenced value (for example pk = :own AND sk = :b AND sk = :c) gives different answers for the two bindings.
There was a problem hiding this comment.
In e3e1da1 both policies here expect the one-condition-per-key ValidationException, which the service returned for these requests on 19 Nov. Without the fix this assertion fails with AccessDeniedException. test_duplicate_key_condition_is_refused_before_leading_keys sends pk = :own AND sk = :b AND sk = :c and the other eight shapes from your 12 Nov comment to six principals.
| ) | ||
| ) | ||
| assert code == "ValidationException" | ||
| assert UNDEFINED_NAME in msg |
There was a problem hiding this comment.
UNDEFINED_NAME in msg passes on a message without the Invalid KeyConditionExpression: prefix. The service answers the exact text in UNDEFINED_NAME_EXACT.
Main is 241 commits ahead of the branch point, and the merge is clean. Three files changed on both sides. crates/core/src/expression/mod.rs: main exports removes_only, and this branch exports parse_key_condition_with_maps. crates/engine/src/query.rs: when the request has an ExclusiveStartKey, main runs the Select check for an index after the start key checks. Main also adds the start key bounds check. This branch changes the key condition parse further down the same function. crates/server/src/leading_keys.rs: main makes extract_typed_value visible to the crate, and this branch changes query_leading_keys.
The branch made authorization run the one-condition-per-key check, so a key condition with two conditions on one key attribute left dynamodb:LeadingKeys absent. Main bound the partition equality's value for such a condition. Which value the service binds for it is not measured. This restores main's binding: crates/server/src/leading_keys.rs is main's code again, and key_condition_clause_operands takes the tokens alone, as on main. The answers differ for `pk = :own AND sk = :b AND sk = :c`. With main's binding, a principal fenced to `own` by ForAnyValue:StringEquals reaches the engine and gets the one-condition-per-key ValidationException. With the key absent, it got AccessDeniedException. A unit test in leading_keys/tests.rs and a wire test in tests/test_fgac_leading_keys.py pin main's answer. The engine refuses every such key condition, so it reads no item either way.
parse_key_condition_with_maps reported an undefined reference only when the key condition also had a second condition on one key attribute. It checked every #name before any :value. Without a duplicate, the classifier reported an undefined #name later. An undefined :value reached the storage query builders, which refused it without the `Invalid KeyConditionExpression: ` prefix. The parse now takes the request's ExpressionMaps and checks, after the grammar and before any clause is classified: 1. Every #name and :value reference, once, in the order the expression is written. The first undefined one is refused with the prefix, with or without a duplicate. The engine's unused name and value check runs after the parse, so an undefined reference comes first. 2. A begins_with operand that is not a string or a binary value. 3. A second condition on one key attribute. `<>` and `contains` are parsed as clauses and refused after these checks, with the messages they had. Measured in us-east-1 on 10 and 11 Nov 2026, two sends each, the same answer both times: - `pk = :q AND #u = :c` with no maps answers `:q`. - `sk = :b AND pk = :a` with no values answers `:b`. - `pk = :a AND pk = :b AND #u = :c` with no maps answers `:a`. The core test that expected `#u` for this request now expects `:a`. - `pk = :q AND pk = :b AND #u = :c` with `:b` and `:c` defined answers `:q`. - `#u = :a AND #u = :b` with no maps answers `#u`. - `pk = :a AND sk = :missing` with an unused `:extra` answers `:missing`, and `pk = :v` or `#k = :v` with an unused name or value answers the undefined reference. - `pk = :a AND pk <> :b` and `pk = :a AND contains(pk, :b)` answer the one-condition-per-key message. - `pk = :a AND begins_with(sk, :n) AND sk = :b` with `:n` a number answers "Incorrect operand type for operator or function; operator or function: begins_with, operand type: N". Without a duplicate, the begins_with operand check now also runs ahead of the key value type check. The service's order for that request is not measured. The undefined name message has one copy in key_condition.rs, and the undefined value message comes from ExpressionMaps::resolve_value_for.
The branch refused a key condition with two conditions on one key attribute after the table, index, ConsistentRead and Select checks. It refused it ahead of the FilterExpression checks. The service runs both the other way round. Measured in us-east-1 on 11 Nov 2026, two sends each, the same answer both times. The table has pk (S) HASH, sk (S) RANGE and a KEYS_ONLY global secondary index on g (S). The key condition is `pk = :a AND pk = :b`: - A missing table, IndexName `nope`, ConsistentRead on the index, Select `BOGUS` and Select `ALL_ATTRIBUTES` on the index each answer the one-condition-per-key message. - A FilterExpression `#q = :a` with `#q` undefined, `foo = :zz` with `:zz` undefined, `begins_with(foo, :n)` with `:n` a number, `name = :a` (a reserved word) and `zz = = :a` each answer the filter's own message. handle_query now parses the key condition right after deserialization. When the parse answers the one-condition-per-key message, the filter's grammar, reserved word, reference and operand type checks run. The first fault they find is returned, and otherwise the duplicate. Any other fault of the parse is reported further down, where it was. An invalid Select is left out of the typed input and its error is returned after this check. The parse result is used further down, so the key condition is parsed once. tests/test_query_key_condition_one_per_key.py pins the measured rows. Its table gets the KEYS_ONLY index. For `zz = = :a` the test compares the expression the error names. ExtendDB words its filter syntax errors differently from the service.
test_undefined_name_reported_ahead_of_duplicate checked that the message contained the undefined name text. It passed on a message without the `Invalid KeyConditionExpression: ` prefix. It now compares the whole message with UNDEFINED_NAME_EXACT. That is the service's text for `#u = :a AND #u = :b` with no ExpressionAttributeNames, measured in us-east-1 on 24 Oct 2026.
tests/test_query_key_condition_one_per_key.py gets the requests behind the reference order and operator change, each with the service's answer: - The first undefined reference in the order the expression is written, a #name or a :value, with or without a duplicate. Measured in us-east-1 on 11 Nov 2026. - An undefined reference ahead of an unused name or value (measured on 10 and 11 Nov 2026). The 10 Nov rows were sent to a table keyed on pk (S) alone. The test table also has sk (S) as its sort key, and none of these requests names it. - `pk = :a AND pk <> :b` and `pk = :a AND contains(pk, :b)` answer the one-condition-per-key message (measured on 11 Nov 2026). - `pk = :a AND begins_with(sk, :n) AND sk = :b` with `:n` a number answers the begins_with operand type message (measured on 11 Nov 2026). Every send in both runs got the same answer twice.
… guard resolve_multipart_with refused a second condition on one key attribute with its own copy of the message. The engine never reaches that branch with a duplicate, since parse_key_condition_with_maps refuses one before the clauses are classified. Authorization still parses with the map-less parse_key_condition when it finds dynamodb:LeadingKeys, and keeps the binding it had for such a condition. On a multi-attribute key schema the branch is what refuses the duplicate there. The branch stays, with a comment that says so, and returns ONE_CONDITION_PER_KEY_ERR. No answer changes.
key_condition_duplicate_check_order_matches_the_service repeated eight order rows that the core tests and the wire file already cover. What it adds is that parse_key_condition_expr passes the request's maps to the parse, with the `#` and `:` keys a request carries. Two rows show that: `#p = :a AND pk = :b` with `#p` defined as pk answers the one-condition-per-key message, and `pk = :a AND pk = :b AND #u = :c` answers the undefined name message for `#u`. The test is renamed key_condition_parse_reads_the_request_maps, and the file is 74 lines shorter.
Earlier commits on this branch left five spots unformatted. cargo +1.97.0 fmt --all rewraps a statement, a constant, three test table rows and an assertion in key_condition.rs. It also joins one loop header in leading_keys/tests.rs. No code changes.
resolve_multipart_with refused a second condition on one key attribute with its own copy of the check. No request reaches it with one. The engine refuses a duplicate in parse_key_condition_with_maps before any clause is classified. Authorization refuses one before the IAM decision (refuse_duplicate_key_condition), ahead of the map-less parse_key_condition it reads for dynamodb:LeadingKeys. The sorts that put the HASH and RANGE equalities in key-schema order stay, with a comment that says what they are for. The thirteen multi-attribute shapes of a_second_condition_on_one_key_attribute_is_refused move into the table of duplicate_condition_on_one_key_attribute_rejected, so they run through the parse that refuses them. The doc comments of resolve_multipart and resolve_multipart_with no longer list the check.
parse_clauses returned RawClause::Unsupported for a `<>` or `contains` clause, so that the duplicate check could read its attribute. classify_clauses refused such a clause before any clause reached raw_to_sk or key_condition_clause_operands. Both still had to match the variant, in arms no input reaches, and raw_to_sk returned a Result for that arm alone. The parser now returns a Clause: a RawClause that a key condition supports, or the path and message of a clause it does not. The reference, begins_with and duplicate checks read Clause. refuse_unsupported_clauses refuses the first unsupported clause and returns the RawClauses. raw_to_sk is main's infallible function again, and the two arms are gone. No answer changes.
check_request parsed the whole KeyConditionExpression before
handle_query read the table. So the shape refusals of classify_clauses
answered ahead of the table, index, ConsistentRead and Select checks.
Main and DynamoDB answer those checks first for these key conditions.
On us-east-1, on 23 Nov, each of these went twice to a table that does
not exist:
pk > :a ResourceNotFoundException: Requested resource not found
pk > :a AND sk > :b ResourceNotFoundException: Requested resource not found
Before this commit the branch answered "partition key condition must
use equality (=)" and "one condition must be an equality on the
partition key".
parse_key_condition_with_maps still refuses the faults that come after
the grammar and before the table on the service. These are the
references in written order, the begins_with operand type, the
duplicate, and the <> and contains refusal. It now returns a fault of
the shape inside Ok. handle_query returns that fault where main parsed
the key condition: after the ConsistentRead and Select index checks,
and before the vector index refusal.
The wire tests add both requests as R10 and R11. A core test checks
that the parse passes three shape faults and returns each refusal
inside Ok.
check_begins_with_operands wrote out the begins_with operand type check and message a second time, beside validate_begins_with_operands in resolver.rs. check_begins_with_operand in resolver.rs now refuses a :value that is not a string or a binary value, with a prefix the caller gives. Both checks call it: the key condition check with its Invalid KeyConditionExpression prefix, as before, and the filter and condition check with none, as before. No answer changes.
… only parse_filter_expression checks a FilterExpression's begins_with and ordering operand types against the request's values. Beside legacy KeyConditions, handle_query checked them a second time, against the request's values with the desugared KeyConditions values added. The desugar adds only _kc_ placeholders. So that pass repeated the first one. The second pass now runs only for a desugared QueryFilter, whose values the first pass does not see. One answer changes. A FilterExpression can name a _kc_ placeholder that the request also defines. The first pass checks the request's value, and the second pass checked the KeyConditions value that replaces it in the merged map.
The doc comment of Names::key_condition in request_attributes.rs said that it reads a key condition as parse_key_condition_expr reads it. The engine parse now reads the request's ExpressionAttributeNames and ExpressionAttributeValues and refuses more. The comment now says that this function reads the clause paths with the map-less parse_key_condition. That parse accepts key conditions that the engine refuses for an undefined reference, a begins_with operand type or a second condition on one key attribute.
test_unreadable_partition_equality_does_not_bind_another_clause also
sent its two key conditions with :u = {"N": "bob"}, and it checked only
the error code. Authorization refuses the duplicate before it reads any
value, so those requests took the path of the readable ones. DynamoDB
answers them with "The parameter cannot be converted to a numeric
value: bob" (us-east-1, 23 Nov, two sends each). This server answers
the one-condition-per-key text, and the check of those numbers is the
subject of #544. The test keeps the readable rows, under the name
test_partition_equality_does_not_bind_another_clause.
The module docstring of test_query_key_condition_one_per_key.py drops
its issue number. The TestOneConditionPerKey docstring no longer says
that the class holds every measured duplicate shape. The reserved word
row of 24 Oct is not in its table.
The upgrade manual had no entry for this change. A key condition with two conditions on one key attribute now gets the ValidationException for every principal, ahead of the IAM decision. Two FilterExpression shapes that 1.0.0 ran are refused too. The new v1.1.0 entry lists them. It also says that the 0.1.15 LeadingKeys entry does not hold for a key condition with two conditions on one key attribute.
|
@pdf-amzn On the two open items of your 10 Nov review, combining this PR with #479 and which one drops its copy:
On the classifier's duplicate check: on 11 Nov I kept it as the guard of the map-less |
The size check added every clause into the HASH or RANGE total, including a second clause on one key attribute. `pk = :a AND pk = :b` with 1025 bytes in each value got the aggregated hash sentence. `pk = :p AND sk = :a AND sk = :b` with 600 bytes in each got the range sentence. Main serves both. DynamoDB refuses both with `Invalid KeyConditionExpression: KeyConditionExpressions must only contain one condition per key`. The `pk` shape is from a measurement on 2026-11-24 in us-east-1 (sent twice), and #489 records the `sk` shape. Each key attribute now contributes its largest value once, and the single hash check reads that value. The one-condition-per-key refusal is #484's. Two rows join the equality table.
demohan
left a comment
There was a problem hiding this comment.
The items from the earlier rounds are resolved at 98d09b3, with one exception, which 19bb1dd introduced (inline).
- Filter faults, then the duplicate, then the table, index, ConsistentRead and Select checks, then written-order references, operators and
begins_withoperand types: on a SQLite build of the head, these answer as the service answers. Each row was sent twice to both. On the merge-base most of these rows answer differently. - The duplicate is refused before LeadingKeys. A principal with an explicit Deny on the table and a principal with no policy get the same one-condition-per-key text on an existing table, a missing table, a missing index and a GSI. Malformed requests without a duplicate still answer AccessDeniedException.
check_requestreads no storage and takes no lock on this path. 1,000 Queries with a 3.9 KB key condition ran within noise of 9733e94. - Each new test fails with its fix reverted. CI is green on 64 of 64 checks, and the new wire file passes 98 of 98 on all four backends.
I will approve once the order in the inline comment is restored. The pk = :a AND name = :b reserved-word order stays with #1007.
| // Parsed and checked above. A fault in its shape answers here, after | ||
| // the table checks (measured 2026-11-23: `pk > :a` on a table that does | ||
| // not exist answers ResourceNotFoundException). | ||
| (parsed?, None) |
There was a problem hiding this comment.
Since 19bb1dd the shape fault is unwrapped after validate_query_select_index_support (line 121), and the service answers it first. This request was sent four times to each target:
{"TableName": "t", "IndexName": "gix", "Select": "ALL_ATTRIBUTES", "KeyConditionExpression": "gpk > :a", "ExpressionAttributeValues": {":a": {"S": "x"}}} on a KEYS_ONLY GSI.
- Service:
ValidationException: Query key condition not supported - 9733e94:
Invalid KeyConditionExpression: partition key condition must use equality (=) - This head:
One or more parameter values were invalid: Select type ALL_ATTRIBUTES is not supported for global secondary index gix because its projection type is not ALL
pk > :a AND sk > :b and begins_with(pk, :a) behave the same way. The measured order puts the shape check after the table, index and ConsistentRead checks and before the Select index check. The commit message says the service answers the Select check first, which holds for Select BOGUS and not for this case.
There was a problem hiding this comment.
You're right about the service. On 24 Nov, on a table with a KEYS_ONLY index and Select ALL_ATTRIBUTES, gpk > :a, gpk > :a AND gsk > :b and begins_with(gpk, :a) answered Query key condition not supported, two sends each. A missed key schema element, a key value of the wrong type, an unused value and a ProjectionExpression also answer ahead of the Select index check.
Main answers the Select index error first for all of these, and this PR keeps main's order, so it changes none of these answers. Moving the check would change answers that this fix does not touch, so I left the order to #1208, which covers Query's check order. The rows are in the comment on #1208. The description now says what the service does and lists the rows under What stays different from DynamoDB.
Main is 13 commits ahead of the branch, and the merge is clean. Three files changed on both sides and merged without a conflict: crates/core/src/expression/resolver.rs, crates/engine/src/lib.rs and docs/manuals/07-upgrade-manual.md.
…ct index check Row A3 sends sk > :a to the KEYS_ONLY index g-keys with Select ALL_ATTRIBUTES. On 25 November the service answered Query condition missed key schema element: g to both sends. The engine skips the Select index check for every key condition with no HASH equality. W5 covers only the Query key condition not supported message. On #484 merged with main, ExtendDB answers A3 with the Select index message.
…ty check The new test sends pk > :v and zz > :v to the vector index. The measured table has HASH pk, RANGE sk and a vector index. On 25 November the service answered Query operation not supported on this index type to each of two sends. This branch parses such a key condition and refuses it after the vector index check. On #484 merged with main, ExtendDB answers both with the parser's message: Invalid KeyConditionExpression: partition key condition must use equality (=).
Main is 10 commits ahead of the branch. Two files conflicted. docs/manuals/07-upgrade-manual.md: both sides add a v1.1.0 entry at the same place. Both stay, main's #398 entry first. crates/engine/src/query.rs: #544 (1ddc087) moved the Limit, enum, parameter mix, names and number checks of a Query into query_key_values::validate_query_request_body. That function reads the raw body before deserialization and before the IAM decision. This branch runs its checks in query::request_checks::check_request. The three conflict regions take this branch's side. handle_query reads the request through check_request, and the empty key condition, parameter usage and ConditionalOperator checks stay in check_request_parameters. check_request now starts with validate_query_request_body and drops its own copies of the ReturnConsumedCapacity enum check and the Limit check. check_request_parameters drops its copy of the parameter mix check. The copies of #544 merged first. The Select enum check moves out of validate_query_request_body into validate_query_select, which check_request runs after the FilterExpression and KeyConditionExpression checks, with the same shape fault rule. The measured rows settle the order. An undefined filter name (H3) and a second condition on one key attribute (B4) answer ahead of an invalid Select. An N value that is not a number (f1 of #544) and a Limit of 0 (L7, f3) answer ahead of it. The server's check before the IAM decision no longer includes Select. A principal the policy denies, with an invalid Select, now gets AccessDeniedException where main gave the Select text. That answer is not measured. Both PRs refuse a begins_with value that is not a string or a binary value. This branch's parser check stays, because the measured rows put that refusal ahead of the duplicate check (D3) and in the parse (E1, P1). handle_query now calls refuse_begins_with_on_number (#544) for a legacy KeyConditions request only, so a KeyConditionExpression is not checked twice. Two unit tests of #544 that read the Select answer from validate_query_request_body now read it from validate_query_select.
The merge of main moved the Select check behind the FilterExpression and KeyConditionExpression checks. The check that the server makes before the IAM decision then no longer covered Select. A principal the policy denies got AccessDeniedException for an invalid Select. Main gives that principal the Select text, because #544 checks Select before the IAM decision. refuse_duplicate_key_condition now runs check_request for an invalid Select too. Every principal gets the Select text, or a fault that check_request reports ahead of it. The measured rows still hold. An undefined filter name (H3) and a duplicate (B4) answer ahead of an invalid Select. No row measures the answer for a principal the policy denies. The new test an_invalid_select_is_refused_before_authorization sends pk = :own and pk > :own with Select BOGUS, and the shape of H3. It also deletes the three comment lines above the validate_query_request_body call in check_request, which repeated the list of checks in that function's doc.
The branch of #484 merged main at 5252eda, which adds #544 (1ddc087). Its next commit, 468b256, refuses an invalid Select before the IAM decision. One file conflicted, crates/engine/src/query.rs, in three places. The key schema checks of handle_query: this branch runs them only when the key condition has an equality on the HASH attribute. #544 runs the classifier's type check only on a multi-attribute key schema or for legacy KeyConditions, and #484's branch calls refuse_begins_with_on_number for legacy KeyConditions only. The resolution keeps this branch's guard around their code, and this branch's missed_key_schema_element helper. refuse_without_hash_equality, beside the new doc of check_request_parameters: both stay. The engine refusal drops its call of refuse_begins_with_on_number. With #544 that function refuses a begins_with value that is not a string or a binary value. The parse refuses that value before the table lookup, and lacks_hash_equality holds only for a KeyConditionExpression, so the call could not fail. Rows 6 and the two begins_with rows of 1 November in test_query_lone_non_equality.py stay, and the parse answers them. The test modules: all three stay. The code that only that call needed goes too. KeyCondition::without_equality put a second clause that is a begins_with into sk_condition, where the engine refusal read it. It now keeps the first clause there. Two engine tests called the refusal with a begins_with on a number key: this merge deletes one, and the other keeps its row 6b.
The module docstring of test_query_lone_non_equality.py placed a begins_with on a number HASH attribute after an unused value and an invalid FilterExpression. No row sends that shape beside either fault, and #484's parse refuses that begins_with value ahead of the unused value check of handle_query. Its sentence that no other value is checked also left out the parse's begins_with refusal, which covers any attribute. The docstring now gives each order with the rows that measure it: - two conditions on one attribute ahead of a wrong-typed value - that value ahead of the key schema wording, and after an unused value and an invalid FilterExpression - the operand type message for a begins_with number on a number HASH attribute, in either clause
demohan
left a comment
There was a problem hiding this comment.
The order our inline named is in #1208, and the body lists it under what stays different; with Select: ALL_ATTRIBUTES on a KEYS_ONLY index beside a key condition fault, this head answers the Select text first as main does, where the service answers the key condition fault.
468b256 refuses an invalid Select before the authorization decision. For the table owner this head answers as 468b256's parent on all 25 rows, and the 12 invalid-Select rows match the service in us-east-1 on 11, four sends each. A user with an explicit Deny and a user with no policy, which got AccessDeniedException on 10 of those 12 rows before, now get the Select text or the fault the owner gets, and the answer is the same for an existing and a missing table. Removing the new trigger or checking Select before the filter each fails a test. fmt, clippy, the 1.91.1 check and 1457 engine and server tests are clean, and the one failing CI job, wasm, is main's, which #1482 fixes.
…endDB#481) * fix(query): refuse key condition values over the key size limits Closes ExtendDB#435. The service refuses a Query whose key condition values exceed the key size limits before it reads anything; ExtendDB ran the Query. Measured on 2026-10-23, every row repeated with identical answers: - A HASH value over 2048 bytes: "One or more parameter values were invalid: Size of hashkey has exceeded the maximum size limit of2048 bytes" (no space after "of", as the service writes it). 2048 bytes is accepted. - HASH values that each fit but add up to more than 2048 bytes (an index with two HASH attributes): "One or more parameter values were invalid: Aggregated size of all hash keys has exceeded the size limit of 2048 bytes". A sum of exactly 2048 is accepted. A single oversized value gets the single sentence even when the sum is also over. - RANGE values adding up to more than 1024 bytes, one clause or several: "One or more parameter values were invalid: Aggregated size of all range keys has exceeded the size limit of 1024 bytes". 1024 is accepted. Every operator is sized (=, <, <=, >, >=, begins_with); BETWEEN contributes its larger bound, not the sum of both. - The HASH checks are reported before the RANGE check. - Strings are sized by UTF-8 bytes (683 U+20AC characters, 2049 bytes, refused; 682 plus "xx", 2048 bytes, accepted) and binary values by byte length. Base tables, LSIs, GSIs and legacy KeyConditions behave the same. - An undefined #name or :value in the key condition is reported before the size check. Ordering, measured with a 2049-byte value: filter syntax, unused names and values, index name, ConsistentRead on a GSI, missing table, Limit, projection syntax and overlap, the Select conflicts and the filter operand type are all reported first; the ExclusiveStartKey checks after. The check is crates/core/src/validation/key_size.rs, called from handle_query after the expression validations and before the start key checks. The limits come from the configuration and the sentences name them. Tests: unit tests in validation/key_size/tests.rs and the engine; tests/python/test_query_key_size.py, test_query_key_size_values.py and test_query_key_size_order.py (64 rows) pass against the service. On ExtendDB alone, five rows with two or more RANGE clauses on one index skip until the multi-attribute range change in ExtendDB#429 merges (the handler refuses the shape earlier today); they pass on the merged tree. The undefined-name row stays unit level because the undefined-name refusal for a sort key clause arrives with ExtendDB#479. Pre-existing, measured, not changed here: a BETWEEN with the lower bound above the upper bound is refused by the service with a bound-order sentence; two conditions on one key are refused with "KeyConditionExpressions must only contain one condition per key"; a Number with 39 or more digits is refused with "Attempting to store more than 38 significant digits in a Number"; a FilterExpression on a key attribute is refused with "Filter Expression can only contain non-primary key attributes". ExtendDB accepts all four. * fix(cassandra): pass the bare index name in IndexNotFound so the Query sentence matches the other backends * test(query): skip the idx accept rows on a backend that cannot read a multi-RANGE index The Cassandra backend answers InternalServerError to any Query on an index with several RANGE attributes: its ORDER BY lists sk_* then base_pk and skips the sk2_* to skN_* clustering columns, which Cassandra refuses with "Order by currently only supports the ordering of columns following their declared order in the PRIMARY KEY". require_multi_range now also skips on InternalServerError, so test_one_600_byte_range_value_is_accepted carries the probe like the other idx rows. * test(query): skip later-RANGE accept rows on first-RANGE-only backends Since ExtendDB#429, the MongoDB and Cassandra backends refuse a key condition on a later RANGE attribute of a multi-attribute index with a ValidationException. Two rows of TestGsiQueryKeySize expect such a Query to be served, and they failed on MongoDB. They now skip when a probe gets that refusal, as the multi-range tests on main do. The refusal rows still run on those backends, because the size check answers first. * fix(core): read the key byte size through the key_size module in restorable_item Main added validation/restorable_item.rs, which sizes a backup item's key with key_value_byte_size from the validation module. This branch moved that function into validation/key_size.rs. The call now names the new module, as check_key_size does. * fix(core): check the number rules before sizing a Query key value Query sized an N value in a key condition by its digit string, so an invalid number got the key size sentence. The service checks the number first. Measured 2026-11-20 in us-east-1 on a GSI with HASH n (N), each shape twice: - 2049 or 39 digits answer "Attempting to store more than 38 significant digits in a Number", in KeyConditionExpression and in KeyConditions. - 1 followed by 2100 zeros answers "Number overflow. Attempting to store a number with magnitude larger than supported range". - The service serves 2100 zeros followed by 1. validate_query_key_sizes now passes each N value it reads to validate_and_normalize_number and sizes the normalized digits. Query served a 39-digit value before and refuses it now, as the service does. The doc comment of validate_query_key_sizes no longer lists two shapes as not measured. The wire tests assert both, a HASH sum of exactly 2048 bytes and the aggregated hash sentence over an oversized RANGE value. Both pass against the service. The comment also names a request that ExtendDB serves and the service refuses. The request has an undefined #name in a second clause, on a key schema with one HASH attribute and at most one RANGE attribute. * fix(query): check Select against the GSI projection after the key size With no ExclusiveStartKey, Query checked Select=ALL_ATTRIBUTES against the index projection before the other request checks. The service makes that check after the key size check. With a start key, it also comes after the start key checks. Measured 2026-11-20 in us-east-1 on a KEYS_ONLY GSI with Select=ALL_ATTRIBUTES, each shape twice: - A 2049-byte key value answers the size sentence, with and without an ExclusiveStartKey. - A 1-byte value answers the Select sentence. - Without a start key, Limit 0 and a parameter mix each answer their own refusal ahead of the Select sentence. So do an empty or invalid KeyConditionExpression, a missed key schema element, a wrong-typed key value and a filter or projection fault. ProjectionExpression with ALL_ATTRIBUTES and an unused name or value also come first. ExtendDB answered the Select sentence for all of them. The check now runs once, after the size and start key checks. The comment above the size check no longer says that the type check is still to come. The type check runs above it, in resolve_key_schema_with. The engine test comments cite the measurement dates and region, not local files. * test(query): add the number and Select rows and keep refusal rows visible - test_query_key_size_values.py: rows on a GSI with HASH n (N) for 2049 digits, 39 digits, 1 followed by 2100 zeros and 2100 zeros followed by 1. Each row runs in KeyConditionExpression and in KeyConditions. - test_query_key_size_order.py: rows on a KEYS_ONLY GSI for Select=ALL_ATTRIBUTES with a 2049-byte and a 1-byte value, with and without an ExclusiveStartKey. The Limit 0 row uses the raw_client fixture from conftest.py in place of its own copy. - This commit removes require_multi_range. Neither of its skips fires on any backend at this head. On a refusal row, a 500 or a classifier change turned the row into a skip. - The BETWEEN row is two tests. The refusal half reports its result on MongoDB and Cassandra, where the accept half skips. - The docstrings cite the measurement dates and region, not local files. * docs(core): cite ExtendDB#1214 for the undefined name that Query serves The doc comment of validate_query_key_sizes names one request that ExtendDB serves and the service refuses: an undefined #name in a second key condition clause. ExtendDB#1214 tracks that request. * docs(query): split the long sentences in four new comments Four new comments now use shorter sentences. They are the number rules in sized_clause and its unit test, the undefined #name in validate_query_key_sizes and the Select check in handle_query. They state the same measurements. * fix(core): size a Query key number the validator does not read by its text 001fe29 sized each N value of a key condition after validate_and_normalize_number, so a number written in other Unicode decimal digits got a 400. DynamoDB reads U+FF11 and U+0967 U+0968 as digits. It serves `n = :v` and the KeyConditions form with those values (200, Count 0, measured 2026-11-20 in us-east-1, twice each), and so did the previous head. The size check now calls normalize_number and refuses only the digit count and magnitude faults. A value the validator does not read as a number is sized by its text again, as before 001fe29. The unit table and TestNumberKeyValues gain the two values, in both syntaxes. The Select test uses the shared refused helper. Its 1-byte row without a start key goes, because test_query_start_key_partition.py sends the same request. Two comments are shorter. * fix(core): do not size a Query key N value that is not a number 31159a2 sized an N value that normalize_number does not read as a number by its text. So 2049 `x` or 2049 U+FF11 in a key condition got the hash size sentence. DynamoDB refuses such a value with a number sentence before it looks up the table (measured 2026-11-24 in us-east-1, twice each). 2049 `x` gets `The parameter cannot be converted to a numeric value: ` and the value, in KeyConditionExpression and in KeyConditions. 39 U+FF11 get `Attempting to store more than 38 significant digits in a Number`. Such a value now adds nothing to the size, and ExtendDB serves the Query as main does. The number check of key condition values is ExtendDB#544's. The unit table gains a 2049 `x` row and a 2049 U+FF11 row. * test(query): fold the key size rows into two tables query_key_size_tests.rs had 19 tests that sent rows of the core tests through the expression parser. The wire files send the same rows end to end. The file keeps the two tests that add a path: the clause order in the expression, and the KeyConditions desugaring. The comments of two deleted index tests named a gate that b116a46 took out. In the core tests, one table holds the equality rows on the base table, on `idx` and on `two-hash`. A second table holds the six undefined-reference rows. Each row keeps its measurement comment. Two rows have measurements from 2026-11-20 on `two-hash`, and their comments no longer say "Not measured". They are a HASH sum of exactly 2048 bytes, and the aggregated hash sentence with a 1025-byte RANGE value. Two tests checked the end of a sentence that a table row asserts in full, and they are gone. * fix(core): count each key attribute once in the Query key size The size check added every clause into the HASH or RANGE total, including a second clause on one key attribute. `pk = :a AND pk = :b` with 1025 bytes in each value got the aggregated hash sentence. `pk = :p AND sk = :a AND sk = :b` with 600 bytes in each got the range sentence. Main serves both. DynamoDB refuses both with `Invalid KeyConditionExpression: KeyConditionExpressions must only contain one condition per key`. The `pk` shape is from a measurement on 2026-11-24 in us-east-1 (sent twice), and ExtendDB#489 records the `sk` shape. Each key attribute now contributes its largest value once, and the single hash check reads that value. The one-condition-per-key refusal is ExtendDB#484's. Two rows join the equality table. * style(core): clear the clippy warnings in the Query key size code The pedantic clippy run flagged `ExtendDB` without backticks in the doc comment of validate_query_key_sizes (doc_markdown). The two tables of 762d4a8 tripped type_complexity, a default lint that CI's `-D warnings` refuses. Each table now names its row type. After this commit, clippy with `-W clippy::pedantic` and `--all-targets` on extenddb-core and extenddb-engine reports no warning on a line this PR adds. * test(query): rename the isrefused tests and reuse assert_validation Nine test names in test_query_key_size.py read `isrefused`, and they now read `is_refused`. `refused` in query_key_size_support.py repeated the three asserts of helpers.assert_validation. It now calls that helper and takes its `code` argument. In test_query_key_size_order.py, `_first` and five tests made the same three asserts after `_error`, and they now call `refused`. `_error` stays for the two syntax error tests, which check the start of the message. * docs(query): count one sort key value per attribute in the limits table 482bf8a counts the largest value of each key attribute once. The sort key row of docs/dynamodb-limits.md said that the Query check adds up every sort key clause. It now says that the check adds up the sort key values of the key condition, one per attribute. * fix(core): refuse a Query key N value that is not a number a3f733d sized an N value that normalize_number does not read as a number as 0 bytes, so the Query went on to storage. On SQLite at 1e5f4bc, `abc`, 2049 `x`, `" 1"` and the empty value answered HTTP 200 with Count 0. That was the answer on a GSI keyed on an N attribute, in KeyConditions and on the base table's N partition key. On the base table's N sort key they answered InternalServerError, and the server log shows `invalid numeric sort key: invalid digit found in string`. DynamoDB refuses each of these values with `The parameter cannot be converted to a numeric value: ` followed by the value as sent. The empty value gets the colon too (measured 2026-11-24 in us-east-1, twice each, in KeyConditionExpression and in KeyConditions). sized_clause now refuses such a value with that text when the value holds ASCII characters only. NumberFault::Empty has no colon, so the refusal uses the text of NumberFault::Malformed. A value with a character outside ASCII still adds nothing to the size. The service reads Unicode decimal digits as digits, and the number rules do not (ExtendDB#565). A refusal here would refuse one U+FF11, which the service reads as the number 1. The unit table now expects the sentence for 2049 `x`. It gains rows for `abc`, `" 1"`, the empty value, and `1e-131` as a partition key value and as a sort key value. * test(query): pin the number sentences in each Query key position test_query_key_size_values.py gains a table for N values that the service refuses as numbers: `abc`, 2049 `x`, `" 1"`, the empty value and `1e-131`. Each row runs in four forms. Two are on a GSI keyed on an N attribute, in KeyConditionExpression and in KeyConditions. The other two use the N partition key and the N sort key of a new `number_table` fixture. Each row asserts status, code and message by equality. The service gives these answers before the table lookup (measured 2026-11-24 in us-east-1, twice each, on a table that does not exist). Two more rows, 39 and 683 U+FF11, assert the service's 38-digit sentence. They are expected failures on ExtendDB, because the number rules do not read U+FF11 as a digit (ExtendDB#565). The mark is not strict, so a check that reads these digits makes the rows of its form pass. The existing number test now builds its Query with the same helper. On a server built from 1e5f4bc, the 16 rows for `abc`, 2049 `x`, `" 1"` and the empty value fail. 12 of them get HTTP 200, and the 4 on the sort key get InternalServerError. The 4 underflow rows pass there too. With 1fe3f0c, the three wire files pass on SQLite: 99 passed and 8 expected failures. * test(query): leave the U+FF11 rows to ExtendDB#565 The files in tests/python hold no expected failures (tests/python/README.md, Design Principles). The rows for 39 and 683 U+FF11 assert the service's 38-digit sentence. ExtendDB gives that sentence only once its number rules read Unicode decimal digits, which is ExtendDB#565, so the rows and their mark go. The measurements of 2026-11-24 are on ExtendDB#565. * test(query): pin the Select order on a KEYS_ONLY GSI without a start key On a KEYS_ONLY GSI with Select ALL_ATTRIBUTES and no ExclusiveStartKey, DynamoDB answers each of these refusals before the Select sentence: - Limit 0 - a key condition on the base table's partition key - an N value on the S key - an unused expression value - an empty KeyConditionExpression - FilterExpression `#` A reviewer measured each shape twice on 2026-11-24. These shapes are now rows of test_select_all_attributes_on_a_keys_only_gsi_is_reported_after. Each row asserts status, code and message by equality, except the `#` row. ExtendDB words that syntax error in its own way (ExtendDB#1419), so the row checks the `Invalid FilterExpression: ` label. The table now sends its requests through raw_client, because the SDK refuses Limit 0. FILTER_LABEL, LIMIT_MESSAGE and MISSED_G_MESSAGE hold the three texts that a new row shares with an existing test. With the Select check moved above the Limit check, the six new rows fail. The two 2049-byte rows of the table and two start key rows in test_query_start_key_partition.py fail too. On SQLite, the three wire files and test_query_start_key_partition.py give 136 passed.
Changes since the last review
crates/engine/src/query.rsanddocs/manuals/07-upgrade-manual.mdconflicted.Limit, enum, parameter mixing, names and number checks of aQueryintovalidate_query_request_body. That function reads the raw body before deserialization and before the IAM decision.check_requestnow starts with that function and drops its own copies of theReturnConsumedCapacityandLimitchecks.check_request_parametersdrops its copy of the parameter mixing check.Selectcheck moves out ofvalidate_query_request_bodyintovalidate_query_select.check_requestreports its error after the filter and key condition checks, with fix(query): check Query values against the key schema and the number rules #544's shape fault rule. The measured rows settle that order. H3 and B4 answer ahead of an invalidSelect. fix(query): check Query values against the key schema and the number rules #544's f1 and f3 and L7 answer ahead of it too. The server's check before the IAM decision then no longer includedSelect. 468b256 checksSelectthere again.begins_withvalue that is not a string or a binary value. The parse keeps this PR's check, because D3 and P1 need the refusal there.handle_querycalls fix(query): check Query values against the key schema and the number rules #544'srefuse_begins_with_on_numberfor a legacyKeyConditionsrequest only.Selectanswer fromvalidate_query_select.Selectbefore the IAM decision, where fix(query): check Query values against the key schema and the number rules #544 put that check on main.Selectmakes the server runcheck_request, as a duplicate does. Every principal gets theSelecttext, or a fault thatcheck_requestreports ahead of it (H3, B4). Item 14 under What gives the answer that changes.an_invalid_select_is_refused_before_authorizationincrates/engine/src/query/request_checks.rssendspk = :ownandpk > :ownwithSelectBOGUS, and the shape of H3.check_requestthat repeated the doc ofvalidate_query_request_body.resolve_multipart_with). No request reached it. The engine refuses a duplicate inparse_key_condition_with_mapsbefore it classifies any clause, and authorization refuses one before the IAM decision. Its 13 multi-attribute rows now run throughparse_key_condition_with_maps.<>andcontainsclauses out ofRawClause. Soraw_to_skis main's infallible function again, and two match arms that no input reached are gone.ConsistentReadandSelectchecks, as main does. The service answers it after the table (R10, R11), the index (S7),ConsistentRead(S6) and an invalidSelect(Q1), and before theSelectindex check (S1). What stays different from DynamoDB lists that order. The reviewed head answered the shape fault ahead of all of these checks.begins_withoperand checks call one helper,check_begins_with_operand.QueryFilter. BesideKeyConditionsit repeated the first check.request_attributes.rs.:u = {"N": "bob"}requests oftest_unreadable_partition_equality_does_not_bind_another_clause, which checked only the error code, and renames the testtest_partition_equality_does_not_bind_another_clause. It also drops two issue numbers from test comments.query_key_values.rsadds 29 of them, forvalidate_query_select, and 468b256 adds 2.Selectindex rows of that day (Q1, S1 to S8, X1, X2, W1 to W5). They give the order of theSelectindex check against the key condition's shape and four other faults. The code is unchanged.What
Querynow refuses aKeyConditionExpressionwith two conditions on one key attribute. The refusal has the service's text,Invalid KeyConditionExpression: KeyConditionExpressions must only contain one condition per key.parse_key_condition_with_mapsincrates/core/src/expression/key_condition.rsmakes the check. Two clauses name the same attribute when their paths resolve to the same name, written as a plain name or as a#namereference. The engine parses the key condition for every storage backend, so the refusal applies on SQLite, PostgreSQL, MongoDB and Cassandra. No storage backend changed.handle_queryincrates/engine/src/query.rsnow checks everyQueryin one order:validate_query_request_body, which fix(query): check Query values against the key schema and the number rules #544 added to main:Limit, theReturnConsumedCapacityvalue, parameter mixing, theExpressionAttributeNamesmap and every number inExpressionAttributeValues. Then deserialization. The handler removes an invalidSelectfrom the body before deserialization and keeps its error. With fix(query): check Query values against the key schema and the number rules #544's shape fault rule, a member of the wrong JSON type answers ahead of that error. Otherwise theSelecterror answers at step 5.check_request_parameters, which are main's code in main's order: an emptyKeyConditionExpression, names or values with no expression, andConditionalOperatorusage. This branch's copies of theLimit,ReturnConsumedCapacityand parameter mixing checks are gone. Step 1 makes those checks with fix(query): check Query values against the key schema and the number rules #544's code.FilterExpressionfault, in main's relative order: grammar and reserved words, then undefined#namereferences, then thebegins_withand ordering operand types, then undefined:valuereferences. The read uses the filter that this step parses.KeyConditionExpressionfault except its shape: reserved words and grammar (syntax, redundant parentheses, nested paths), then undefined#nameand:valuereferences in written order. Then come thebegins_withoperand type, the duplicate, and last<>andcontains.Select, the table, the index,ConsistentReadand theSelectindex check.parse_key_condition_with_mapsreturns a shape fault insideOk, andhandle_queryreturns it here. The legacyKeyConditionsdesugar, the vector index refusal, the key schema checks, projection and the unused name and value checks follow, as on main. Among them,handle_querycalls fix(query): check Query values against the key schema and the number rules #544'srefuse_begins_with_on_numberfor a legacyKeyConditionsrequest only, because step 4 refuses the same value in aKeyConditionExpression.On the expression path, an undefined key condition
:valueno longer reaches the storage query builders. PartiQLSELECTreacheshandle_querythrough its translation. Its key conditions hold one partition key equality and at most one sort key condition, on distinct#namereferences that are all defined. So the duplicate and reference refusals cannot fire there.For every
Query,authorize_requestcallsrefuse_duplicate_key_conditionbefore the IAM decision. When the key condition has two conditions on one attribute, or theSelectvalue is invalid, that function runscheck_requestand returns its error.check_requestmakes the checks above that come before the table read. So every principal gets the answer the table owner gets. For a duplicate, that answer is the one-condition-per-key text, or a fault that the service reports ahead of it. Main answered AccessDeniedException to a principal whose policy denied such a request. Item 14 under Answers that change against main gives the answers for an invalidSelect.DynamoDB refuses the duplicate before it evaluates the policy. On 19 Nov, 9 duplicate shapes went twice to the table owner and to 6 roles. Four roles had a
dynamodb:LeadingKeyscondition, one had no Allow fordynamodb:Query, and one had a Deny on it. All 126 requests gotInvalid KeyConditionExpression: KeyConditionExpressions must only contain one condition per key. BesideLimit0, an undefined#qin the filter or an undefined#uin the key condition, every principal got that fault.Authorization passes
leading_keys::names_mapto that function as the request's names, sonames_mapis nowpub(crate). Apart from that,crates/server/src/leading_keys.rsis main's code. A key condition without a duplicate goes to the IAM decision, anddynamodb:LeadingKeysbinds through the map-lesskey_condition_clause_operandsandparse_key_condition, as on main.key_condition.rswas over 600 lines on main, and this change does not split it. Against main at 5252eda the PR adds 591 production lines and removes 187. It adds 1017 test lines and removes 53.Answers that change against main
The row labels refer to the measurements under Why. "10 Nov" is the set of 10 November.
With one fault in the request:
:value, with theInvalid KeyConditionExpression:prefix. Main refused it in the storage query builder, without the prefix. Rows C1, C2, C3, C5, F1e and 10 Nov.#namethat main treated as a missing key, such as#k = :v, answers the undefined name. Main answered "Query condition missed key schema element: pk". 10 Nov.:valuebefore the read, also on a partition with no items, where main servedCount0. F3.begins_with(pk, :n)with a number answers the operand type message. Main answered "partition key condition must use equality (=)". P1.With two faults in the request, where the order changed:
check_request_parametersanswer ahead of the table checks, which main runs first.KeyConditionExpression(M2) andConditionalOperatorwith noQueryFilter(M3) answer ahead of a missing table.SelectorConsistentReadfault. They follow the same order.IndexNamenope,SelectBOGUSandConsistentReadon a GSI: H1 to H4begins_withon an S sort key: F1fKeyConditionsdesugar errors and the vector index refusal:valueanswers ahead of projection faults, unused names or values,Selectand projection conflicts, andExclusiveStartKeyfaults. Main refused it at evaluation. This follows F3 and F1d and is not measured against each.SelectBOGUS, a missing table,IndexNamenopeandConsistentReadon a GSI, which main answered first. They are the size and token limits, reserved words and grammar, undefined references, thebegins_withoperand type, the duplicate, and<>andcontains.begins_withnumber, R7 for<>and R8 for a nested path.SelectBOGUS(Q1), a missing table (R10, R11),IndexNamenope(S7) andConsistentReadon a GSI (S6), as on main.SelectBOGUSanswers after a filter fault (H3) and a key condition fault (B4, the duplicate), which main checks after it. It answers afterLimit(L7) and parameter mixing (F2c), as on main since fix(query): check Query values against the key schema and the number rules #544.<>andcontainsclauses answer after an undefined name (E2, E3), a later syntax error (E10) and a nested path in another clause. R8 measures the nested path in the first clause. Main answered the operator refusal.IndexNamenaming a vector index, a key condition reference fault orbegins_withoperand fault answers ahead of the vector index refusal. Not measured.FilterExpressionthat names an internal legacy placeholder such as:_kc_pk, besideKeyConditions, as undefined, as the service does (R9). Main resolved it from the desugaredKeyConditions. When the request defines:_kc_pk, the filter's operand check reads the request's value, where main read theKeyConditionsvalue.Selectbeside a filter fault or a key condition fault answers that fault. Main answers theSelecttext, because fix(query): check Query values against the key schema and the number rules #544 checksSelectbefore the IAM decision. This branch refuses an invalidSelectbefore the IAM decision too, after the filter and key condition checks (H3, B4). The answer for such a principal is not measured. With no other fault, every principal gets theSelecttext, as on main.Some orders stay as on main. With one fault, a number in
begins_withon an S sort key (E1) answers thebegins_withoperand type message, as on main since #544.Limitcomes ahead of the parameter, filter and key condition checks (L2 to L5), a missing table (L6) andSelectBOGUS(L7). #544 gave main that order. BesideIndexNamenope,ConsistentReadon a GSI orSelectALL_ATTRIBUTESon a KEYS_ONLY index,Limit0 is not measured. Parameter mixing comes ahead of a filter fault (H5). It also comes ahead of a missing table,IndexNamenope,SelectBOGUSandConsistentReadon a GSI (F2a to F2d). The order inside the filter is main's, and F1, F1b, F1c and F1d answer as on main. A fault in the key condition's shape answers after the table, index,ConsistentReadandSelectchecks, as on main. The service answers it after the table (R10, R11), the index (S7),ConsistentRead(S6) and an invalidSelect(Q1), and before theSelectindex check (S1).What stays different from DynamoDB
<>andcontainskeep main's texts (Query: shapes the service refuses that ExtendDB accepts or words differently (measured 2026-10-23) #489). For E4 (pk = :a AND sk <> :b) and E5 (pk = :a AND contains(sk, :b)), the service answersInvalid KeyConditionExpression: Invalid operator used in KeyConditionExpression. For E6 (pk = :a AND contains(sk)) it answersInvalid KeyConditionExpression: Incorrect number of operands for operator or function; operator or function: contains, number of operands: 1. ExtendDB answersInvalid KeyConditionExpression: Unsupported operator on KeyCondition: NEfor E4 andInvalid KeyConditionExpression: expected comparison operatorfor E5 and E6.zz = = :a(A5, F1b) the service answersInvalid FilterExpression: Syntax error; token: "=", near: "= = :a". ExtendDB answersInvalid FilterExpression: expected attribute path or value placeholder. The tests compare the prefix.Invalid KeyConditionExpression: unexpected end of expression(Query: shapes the service refuses that ExtendDB accepts or words differently (measured 2026-10-23) #489). The service answersInvalid KeyConditionExpression: Syntax error; token: "<EOF>", near: "AND". The test compares the prefix.sk = :x,zz = :xand GSIg1 = :x, each with an unused:y. The service answers the unused value sentence. Query: the missing key refusal comes before the filter syntax and unused value checks when the key condition has an equality #712 stays open.begins_with(pk, :s)with a string (P2, the subject of fix(query): refuse a key condition with no HASH equality the way the service does #479) answers main'sInvalid KeyConditionExpression: partition key condition must use equality (=). The service answersQuery key condition not supported.pk = :a AND zz = :cwithpkHASH andskRANGE (J3), DynamoDB answers "Query condition missed key schema element: sk". ExtendDB answers HTTP 200 and applies the clause to the sort key column. On a hash-only table (J4), DynamoDB answers "The number of query conditions (2) exceeds the number of key attributes defined in the schema (1)". ExtendDB answers HTTP 200 withCount1 and ignores the second condition.<>orcontainsclause beside abegins_withnumber operand in another clause. This branch answers the operand message. Main answers the operator's own message, because its parse stops at that clause. One check order cannot keep main's answer for it and also keep the measured orders.KeyConditions, aFilterExpressionthat names:_kc_pkand defines it inExpressionAttributeValuescompares with theKeyConditionspartition value, as on main (Query: a KeyConditions placeholder replaces a FilterExpression value of the same name #1399). The service's answer with:_kc_pkdefined is not measured.Selectindex check (SelectALL_ATTRIBUTESon a global secondary index whose projection is notALL) answers ahead of five other faults, as on main. They are the key condition's shape, a missed key schema element, a key value of the wrong type, an unused value and aProjectionExpressionbesideALL_ATTRIBUTES. The service answers each of those first (24 Nov). S1, S3, S4 and W5 measure the shape, S5 and W1 the missed key element, and S8 and W2 the type. X1 and W3 measure the unused value, and X2 and W4 the projection. Moving the check would change answers outside this fix. So the order stays with Query looks up the table, the index and ConsistentRead before it checks the expressions, and reads the key condition before the filter #1208, which covers Query's check order and has these rows.Why
Fixes #430.
On main,
Queryserved a key condition with two conditions on one key attribute. Forpk = :a AND pk = :bthe parser read the first equality as the partition key condition and the second as the sort key condition. On a table withpkHASH andskRANGE, the request returned the items in partition:awhose sort key equals:b. DynamoDB refuses these shapes with one message.Every measurement is against DynamoDB in us-east-1. The client sent each row of 31 Oct, 10 Nov, 11 Nov, 19 Nov, 23 Nov and 24 Nov twice. Both sends got the same answer. Each set measured these shapes and orders:
IndexNamethe table does not have.ConsistentReadandSelectchecks (B). Also references in written order (C), and<>,containsandbegins_withbeside a duplicate (D).<>,containsandbegins_withwith and without a duplicate (E1 to E6, E10 to E12). Also parameter mixing ahead of the duplicate (E8, E9).Limitahead of every other check (L1 to L7), and parameter checks ahead of a missing table (M1 to M3). Alsobegins_withon the partition key (P1, P2). The SDK's parameter checks were off, soLimit0 reached the service.Nvalue that is not a number beside a duplicate (R3, R4). A filter that names:_kc_pkbesideKeyConditions(R9).Selectindex check against the key condition's shape and four other faults. The rows (Q1, S1 to S8, X1, X2, W1 to W5) are in the comment on Query looks up the table, the index and ConsistentRead before it checks the expressions, and reads the key condition before the filter #1208.24 and 31 October rows
24 October 2026, 00:27 to 00:37 UTC. The table has
pkS HASH andskS RANGE and holdsalice/bobandalice/carol. boto3 ran with retries off.pk = :apk = :a AND sk = :bsk = :b AND pk = :apk = :a AND sk BETWEEN :b AND :cpk = :a AND begins_with(sk, :b)pk = :a AND pk = :bpk = :a AND pk = :apk = :a AND pk = :b AND sk = :cpk = :a AND pk > :bpk > :b AND pk = :a:a = pk AND pk = :b(pk = :a) AND (pk = :b)pk = :a AND sk = :b AND sk = :cpk = :a AND sk = :b AND sk = :bpk = :a AND sk BETWEEN :b AND :c AND sk = :bpk = :a AND sk BETWEEN :b AND :c AND begins_with(sk, :b)pk = :a AND begins_with(sk, :b) AND sk = :cpk = :a AND sk > :b AND sk < :cpk = :a AND begins_with(sk, :b) AND begins_with(sk, :c)pk = :a AND pk = :b AND sk = :b AND sk = :csk = :b AND sk = :c#p = :a AND pk = :b(#p->pk)#p = :a AND #q = :b(both ->pk)pk = :a AND #s = :b AND sk = :c(#s->sk)pk = :a AND zz = :b AND zz = :cpk = :a AND pk = :bon a hash-only tablepk = :a AND pk.foo = :b((pk = :a)) AND (pk = :b)#u = :a AND #u = :b(#uundefined)pk = :a AND pk = :b AND other = :cbegins_with(pk, :a) AND sk = :bpk BETWEEN :a AND :b31 October 2026, 17:37 UTC, AWS CLI. The table has
pkS HASH andskS RANGE.:a,:b,:care strings and:nis the number 1. Every answer is aValidationException.pk = :a AND pk = :bpk = :a AND pk = :n#p = :a AND pk = :n(#p->pk)pk = :nOne or more parameter values were invalid: Condition parameter type does not match schema typepk = :a AND #s = :b AND sk = :n(#s->sk)#u = :a AND sk = :b AND sk = :c, noExpressionAttributeNamesInvalid KeyConditionExpression: An expression attribute name used in the document path is not defined; attribute name: #upk = :a AND pk = :b AND #u = :c, noExpressionAttributeNames#u#u = :a AND #u > :b, noExpressionAttributeNames#upk = :a AND pk = :b, noExpressionAttributeValuesInvalid KeyConditionExpression: An expression attribute value used in expression is not defined; attribute value: :apk = :a AND pk = :bwith an unused:zinExpressionAttributeValuespk = :a AND pk = :bwithIndexNamenope, an index the table does not have10 and 11 November rows
10 November 2026, 23:33 UTC, on a table keyed on
pk(S) alone. In the answers, "undefined name#x" and "undefined value:x" stand for the service's texts with theInvalid KeyConditionExpression:prefix, or withInvalid FilterExpression:where the row says "filter".pk = :v, only an unused:wdefined:v#k = :v, no names,:vand an unused:wdefined#k#k = :v, an unused#jdefined,:vdefined#kpk = :v, an unused#jand an unused:wdefined:v#k = :v, no names, only an unused:wdefined#k11 November 2026, 09:43 to 14:39 UTC. The table has
pk(S) HASH,sk(S) RANGE and a KEYS_ONLY global secondary indexg-keysong(S). J2 and J4 ran on the hash-only table of 10 Nov.:a,:b,:care strings and:nis a number. A missing table is a table name that does not exist. For F1f, F1g and H1 to H5 the request column comes from the labels recorded with each answer.pk = :a AND pk = :b, FilterExpression#q = :a, no names#qfoo = :zz:zzbegins_with(foo, :n)Invalid FilterExpression: Incorrect operand type for operator or function; operator or function: begins_with, operand type: Nname = :aInvalid FilterExpression: Attribute name is a reserved keyword; reserved keyword: namezz = = :aInvalid FilterExpression: Syntax error; token: "=", near: "= = :a"pk = :a AND pk = :bon a missing table (B1), with IndexNamenope(B2) and with SelectBOGUS(B4).g = :a AND g = :bong-keyswith ConsistentRead (B3) and with SelectALL_ATTRIBUTES(B5)pk = :q AND #u = :c, no names or values:qsk = :b AND pk = :a, no values:bpk = :a AND sk = :missing,:aand an unused:extradefined:missingpk = :a AND pk = :b AND #u = :c, no names or values:apk = :q AND pk = :b AND #u = :c,:band:cdefined:q#u = :a AND #u = :b, no names or values#upk = :b AND pk = :a, no values:bpk = :a AND pk <> :b,pk = :a AND contains(pk, :b)pk = :a AND begins_with(sk, :n) AND sk = :bInvalid KeyConditionExpression: Incorrect operand type for operator or function; operator or function: begins_with, operand type: Npk = :a AND begins_with(sk, :n)pk = :a AND sk <> :b AND #u = :c,pk = :a AND contains(sk, :b) AND #u = :c, no names#upk = :a AND sk <> :b,pk = :a AND contains(sk, :b)Invalid KeyConditionExpression: Invalid operator used in KeyConditionExpressionpk = :a AND contains(sk)Invalid KeyConditionExpression: Incorrect number of operands for operator or function; operator or function: contains, number of operands: 1pk = :a AND pk = :bwith ConditionalOperatorANDand no QueryFilterCan not use both expression and non-expression parameters in the same request: Non-expression parameters: {ConditionalOperator} Expression parameters: {KeyConditionExpression}pk = :a AND pk = :bwith legacy KeyConditions{KeyConditions}pk = :a AND sk <> :b ANDInvalid KeyConditionExpression: Syntax error; token: "<EOF>", near: "AND"pk = :a AND sk <> :b AND sk = :c,pk = :a AND contains(sk, :b) AND sk = :cpk = :a AND sk = :missing, FilterExpression#q = :a, no names#qzz = = :aInvalid FilterExpression: Syntax error; token: "=", near: "= = :a"pk = :a AND #s = :b, no names, FilterExpression#q = :a#qpk = :a AND #s = :b, no names, FilterExpressionfoo = :zz:zzpk = :a AND sk = :missing, FilterExpressionfoo = :a:missingpk = :a AND begins_with(sk, :n), FilterExpression#q = :a#qpk = :a AND, FilterExpression#q = :a#qpk = :awith ConditionalOperatorANDon a missing table (F2a), with IndexNamenope(F2b) and with SelectBOGUS(F2c).g = :aong-keyswith ConditionalOperatorANDand ConsistentRead (F2d)pk = :aon a partition with no items, FilterExpressionfoo = :zz:zzpk = :a, FilterExpression#q = :a, on a missing table (H1), with IndexNamenope(H2) and with SelectBOGUS(H3).g = :aong-keyswith ConsistentRead (H4)#qpk = :a, FilterExpression#q = :a, ConditionalOperatorANDExpression parameters: {FilterExpression, KeyConditionExpression}Limit0 alone (L1), besidepk = :a AND(L2),pk = :a AND pk = :b(L3), FilterExpression#q = :awith no names (L4), ConditionalOperatorAND(L5), a missing table (L6) and SelectBOGUS(L7)1 validation error detected: Value at 'Limit' failed to satisfy constraint: Member must have value greater than or equal to 1begins_with(pk, :n)begins_with(pk, :s),:sa stringQuery key condition not supportedExpressionAttributeValues can only be specified when using expressionsKeyConditionExpression, on a missing tableInvalid KeyConditionExpression: The expression can not be empty;ANDand no QueryFilter, on a missing tableConditionalOperator cannot be used without Filter or Expectedpk = :a AND zz = :b AND zz = :cpk = :a AND pk = :b, on the hash-only tablepk = :a AND zz = :cQuery condition missed key schema element: skpk = :a AND zz = :c, on the hash-only tableThe number of query conditions (2) exceeds the number of key attributes defined in the schema (1)23 November rows
23 November 2026, 16:44 to 17:00 UTC. boto3 ran with retries and parameter validation off. Every request went to a table name that does not exist.
:aisaliceand:bisbob, both strings.:nis the number 1, and:tis the booleantrue.pk = :a AND pk = :b, FilterExpressionzz = = :aValidationExceptionInvalid FilterExpression: Syntax error; token: "=", near: "= = :a"pk = :a AND sk <> :b ANDValidationExceptionInvalid KeyConditionExpression: Syntax error; token: "<EOF>", near: "AND"pk = :u AND pk > :v,:u={"N": "bob"},:v=aliceValidationExceptionThe parameter cannot be converted to a numeric value: bobpk > :v AND pk = :u, the values of R3pk = :q, no valuesValidationExceptionInvalid KeyConditionExpression: An expression attribute value used in expression is not defined; attribute value: :qpk = :a AND begins_with(sk, :n)ValidationExceptionInvalid KeyConditionExpression: Incorrect operand type for operator or function; operator or function: begins_with, operand type: Npk = :a AND sk <> :bValidationExceptionInvalid KeyConditionExpression: Invalid operator used in KeyConditionExpressionpk.x = :a AND sk <> :bValidationExceptionInvalid KeyConditionExpression: KeyConditionExpressions cannot have conditions on nested attributespkEQalice, FilterExpressionfoo = :_kc_pk, no valuesValidationExceptionInvalid FilterExpression: An expression attribute value used in expression is not defined; attribute value: :_kc_pkpk > :aResourceNotFoundExceptionRequested resource not foundpk > :a AND sk > :bResourceNotFoundExceptionRequested resource not foundpk = :a, FilterExpressionbegins_with(foo, :n)ValidationExceptionInvalid FilterExpression: Incorrect operand type for operator or function; operator or function: begins_with, operand type: Npk = :a, FilterExpressionfoo < :tValidationExceptionInvalid FilterExpression: Incorrect operand type for operator or function; operator or function: <, operand type: BOOLOverlap with #479
#479 added three checks that this PR also makes:
KeyCondition::validate_referencesinreferences.rs. It read names before values, each in sorted order. The service names the first undefined reference in written order (C4, C5), ascheck_referenceshere does.ONE_CONDITION_PER_KEYinno_hash_equality.rs, another copy of the text thatONE_CONDITION_PER_KEY_ERRholds here.refuse_two_conditions_on_one_attribute, which refused that text for two non-equality clauses. With this PR,parse_key_condition_with_mapsrefuses every duplicate before it.The two PRs merge in sequence, this PR first. #479 sits on this branch and dropped those three copies in aeec7b0. Its own commits conflict with this branch in
crates/engine/src/query.rs, and its merge commits resolve that.Merging
At 468b256 this branch merges with main at 5252eda without a conflict. At 16:40 UTC on 25 Nov, 105 other open PRs changed a file of this PR or of #479. 42 of them conflict with main themselves and were not checked. 48 merge with this branch without a conflict, and 15 conflict with it:
crates/engine/src/query.rs: fix(engine): send the ConditionalOperator enum text alone on Query and Scan #1100, fix(core): refuse a name that starts with an underscore in an expression #1131, fix(engine): answer a missing TableName, Key or Item as DynamoDB does #1262, fix(expressions): validate in the service's order, with its messages #399, fix(query): refuse key condition values over the key size limits #481 and fix(query): check legacy conditions against the key schema #507crates/engine/src/expression_helpers.rs: fix(core): refuse the list indexes DynamoDB refuses in expression paths #1095, fix(expressions): validate in the service's order, with its messages #399 and fix(query): check legacy conditions against the key schema #507crates/engine/src/query_key_values.rs: fix(query): check the numbers of KeyConditions and QueryFilter values #1364docs/manuals/07-upgrade-manual.md: fix(deps): move to sqlx 0.9.1 for the SQLite fix of RUSTSEC-2026-0459 #1166, fix(storage-mongodb): refuse the request when a stored IAM document cannot be read #1314, fix(server): count a request refused in the authorization step in UserErrors and RequestCount #1427, fix(storage): store U+0000 in strings on PostgreSQL and MongoDB #368, fix(storage-postgres): serve each table in turn in the GSI queue workers #542, fix(config): environment overrides for every backend key; Cassandra refuses unknown keys #546 and fix(server): default dynamodb:Select, ReturnValues and ReturnConsumedCapacity condition keys #738Testing done
New tests in
tests/test_query_key_condition_one_per_key.pycompare the service's whole text, except where a row says "by the prefix":TestDuplicateAheadOfRequestChecks: A1 to A5 (A5 by the prefix), B1 to B5, E8 and E9.TestReferenceAndOperatorOrder: C1 to C7, the 10 Nov rows, D1 to D3, E1 to E3, and E10 (by the prefix) to E12.TestQueryCheckOrder: F1 to F1g (F1b by the prefix), F2a to F2d, F3 and H1 to H5. Also R10 and R11, which expectResourceNotFoundExceptionon a missing table.TestLimitAndParameterChecksFirst: L1 to L7, P1 and M1 to M3. TheLimit0 rows use the suite'sdynamodb_client_no_validationfixture.The classes of the first revision stay:
TestOneConditionPerKey(shapes from 24 Oct) andTestDuplicateCheckOrder(7 of the 31 Oct requests).TestOneConditionPerKeynow also has the J1 and J2 rows. Each class is one table of rows with one parametrizedtest_refused. Core unit tests pin the parse order:first_undefined_reference_in_text_order_is_reported,operators_and_operands_around_the_duplicate_check,other_ne_and_contains_clauses_keep_their_refusalandthe_shape_is_refused_after_the_checks. The last one checks thatparse_key_condition_with_mapsreturns a shape fault insideOk.duplicate_condition_on_one_key_attribute_rejectedalso holds the 13 multi-attribute shapes of the classifier test that 534fb77 removes.test_duplicate_key_condition_is_refused_before_leading_keysintests/test_fgac_leading_keys.pysends the 9 shapes of 19 Nov as 6 principals and expects the one-condition-per-key text. Four principals have adynamodb:LeadingKeyscondition, one has no Allow fordynamodb:Query, and one has a Deny on it. Authorization binds no value for a duplicate now, andcrates/server/src/leading_keys/tests.rsequals main's file.test_partition_equality_does_not_bind_another_clauseis main'stest_unreadable_partition_equality_does_not_bind_another_clause. It sendspk = :u AND pk > :vandpk > :v AND pk = :uwith:uoutside the fence, and expects the one-condition-per-key text for the table owner and both its policies.a_duplicate_gets_the_answer_of_the_table_ownerincrates/engine/src/query/request_checks.rspins the faults that answer ahead of the duplicate in authorization.an_invalid_select_is_refused_before_authorizationin the same file pins the answers there for an invalidSelect: theSelecttext forpk = :ownandpk > :own, and the filter fault for the shape of H3.Checks on the tree of 468b256, with main at 5252eda merged in:
cargo +1.97.0 fmt --all -- --check: exit 0.cargo +1.97.0 clippy --locked -p extenddb-core -p extenddb-engine --all-targets -- -D warnings: exit 0. The same for the engine crate with--features extenddb-engine/backup-test-hooks: exit 0.cargo +1.91.1 check --locked -p extenddb-core -p extenddb-engine --all-targets: exit 0.cargo +1.97.0 test --locked --no-fail-fast -p extenddb-core -p extenddb-engine --lib: core 1183 passed and 1 ignored, engine 937 passed.refuse_duplicate_key_condition(if duplicate),an_invalid_select_is_refused_before_authorizationfails:pk = :ownwithSelectBOGUSanswersOk(()).cargo +1.97.0 test --locked -p extenddb-wasm-adapter --test parity:every_case_gives_its_expected_answerpassed.tests/test_query_key_condition_one_per_key.py(98 tests) andtests/test_fgac_leading_keys.py(32 tests): 130 passed. It ran fix(query): check Query values against the key schema and the number rules #544'stests/test_query_key_value_types.py,tests/test_query_leading_keys_values.pyandtests/test_query_value_shapes.py: 329 passed.python3 -m pytest --collect-only -qoftests/and oftests/python: 7170 and 672 tests, no error.Checks on the tree of b83c3b8:
cargo +1.97.0 fmt --all -- --check: exit 0.cargo +1.97.0 clippy --locked -p extenddb-core -p extenddb-engine -p extenddb-server --all-targets -- -D warnings: exit 0. The same for the engine and server crates with--features extenddb-engine/backup-test-hooks: exit 0.cargo +1.97.0 clippy -- -W clippy::pedanticon the same three crates warns on 6 lines that the PR adds. These are 2 doc comments without backticks, 2HashMapparameters, an item after statements in a test, and a binding name in the moved parameter checks. So the Clippy box stays unticked.cargo +1.91.1 check --locked -p extenddb-core -p extenddb-engine -p extenddb-server --all-targets: exit 0.cargo +1.97.0 test --locked --no-fail-fast -p extenddb-core -p extenddb-engine -p extenddb-server: core 1152 passed, engine 874 passed, server 513 passed and 5 failed.backup_store::tests::a_defaulted_root_with_rows_is_handled_as_a_configured_one,a_permissive_lock_file_is_narrowed,an_existing_spool_must_be_owner_only,an_unreadable_catalog_keeps_a_failing_default_root_configuredandthe_spool_lock_refuses_a_second_instance.backup_store.rsis main's code, and this PR does not change it.tests/test_query_key_condition_one_per_key.py(98 tests) andtests/test_fgac_leading_keys.py(32 tests): 130 passed.ValidationException.Checks on the tree of 3746280 that this round did not repeat:
authorize_requestremoved, the two changed tests intests/test_fgac_leading_keys.pyfail with AccessDeniedException.tests/test_query_key_condition_one_per_key.pyagainst DynamoDB: 96 passed. R10 and R11 come from the 23 Nov measurements, and the file did not run against DynamoDB with them.Checks on the tree of 9733e94, before the authorization change:
cargo +1.97.0 fmt --all -- --check: exit 0.cargo +1.97.0 clippy --locked --all-targets --features extenddb-storage-cassandra/test-hooks,extenddb-storage-mongodb/test-hooks -- -D warnings: exit 0.cargo +1.97.0 clippy --locked --all-targets --features extenddb-engine/backup-test-hooks -- -D warnings: exit 0.cargo +1.97.0 test --locked -p extenddb-core -p extenddb-engine -p extenddb-server: core 1102 passed, engine 769 passed, server 448 passed and 5 failed, the same 5. Core had 1106 before five unit tests became one table.cargo +1.97.0 build --locked -p extenddb --no-default-features --features sqlite) ran the wire tests:devtools/run-tests --extenddb --config <config> --rust-integration --filter query: 47 passed, 0 failed.devtools/run-tests --extenddb --config <config> --pytest --filter "one_per_key or leading_keys or test_query or query_scan or key_condition or KeyCondition or partiql_key or partiql_check_order or conditional_operator": 761 passed, 0 failed.tests/test_query_key_condition_one_per_key.py(96),tests/test_fgac_leading_keys.py(32),tests/test_query_scan.py(116),tests/test_conditional_operator.py(42) andtests/test_partiql_check_order.py(66).run-testsexits 1 on the Python run because its backup store step selects none of its 19 tests under this filter. pytest exits 5 when no test runs.QueryFilterandKeyConditionsrequests. 06d7d20 removes theKeyConditionsone.52a90f6 and 9733e94 change no answer. 52a90f6 runs the filter's operand checks through one helper and cuts the comments that repeated this description. 9733e94 writes the wire tests as tables (925 lines down to 422), and the new file sends the same requests as the old one. At c560e41, with the duplicate check removed from
parse_key_condition_with_maps, the J1 and J2 tests got HTTP 200 and failed.At the first revision, a server built from main failed the duplicate wire tests:
pk = :a AND pk = :banswered 200 withCount1.Not run here:
cargo test --workspace, the whole Python suite, and the MongoDB, PostgreSQL and Cassandra suites. CI runs the MongoDB, PostgreSQL and Cassandra suites.CI at 98d09b3: 64 of 64 checks pass, and no code scanning alert is open.
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
Some
Queryrequests that main served now get an error:FilterExpression:valueon a partition with no items (F3)FilterExpressionthat names an internal legacy placeholder such as:_kc_pk, besideKeyConditions, when the request does not define it (the service refuses it too, R9)For a key condition with two conditions on one key attribute, main answered AccessDeniedException to a principal whose policy does not allow the request. That principal now gets the
ValidationException. Beside an invalidSelect, a filter fault or a key condition fault now answers ahead of theSelecttext for every principal. A request with more than one fault can get a different error than on main, as the list under What gives.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.