Repository navigation
fix(engine): send the ConditionalOperator enum text alone on Query and Scan - #1100
LeeroyHannigan wants to merge 4 commits into
Conversation
…d Scan Query and Scan refuse a ConditionalOperator outside [AND, OR] with a ValidationException. DynamoDB sends the enum text on these two operations without the "1 validation error detected: " prefix. ExtendDB sent it with the prefix, the form DynamoDB uses on PutItem, UpdateItem and DeleteItem. Query and Scan now remove the prefix from that text when they read the request. The checks keep their order. An AttributesToGet string written ahead of an invalid ConditionalOperator still answers SerializationException, the exception DynamoDB sends. PutItem, UpdateItem and DeleteItem keep the prefix. Measured against DynamoDB in us-east-1 on 13, 14 and 17 Nov 2026. Fixes #1049.
hitesh96db
left a comment
There was a problem hiding this comment.
Required: state the scope of the bare clause, or cover the combined form (first inline comment, crates/engine/src/lib.rs). I will approve once that is done. Two optional items are inline.
Also measured, and the same on main, so not a condition here: a wrong AttributeValue datatype in a filter ({"S": 1}) beats an invalid ConditionalOperator on DynamoDB as SerializationException NUMBER_VALUE cannot be converted to String (twice, identical). ExtendDB answers the ConditionalOperator ValidationException.
| } | ||
|
|
||
| /// [`deserialize_error`] for Query and Scan, which send a refused | ||
| /// `ConditionalOperator` as the enum clause alone. PutItem, UpdateItem and |
There was a problem hiding this comment.
This states the rule as "Query and Scan send the enum clause alone". DynamoDB sends the bare clause only when the ConditionalOperator value is the one fault it reports. When the request also holds a fault it reports in the same pass, it sends the counted form with the list as [OR, AND]. Measured in us-east-1 on 2026-11-24, each request twice with identical answers.
Query, entry a of QueryFilter holds an empty AttributeValue ([{}]), "ConditionalOperator": "XOR":
- DynamoDB:
1 validation error detected: Value 'XOR' at 'conditionalOperator' failed to satisfy constraint: Member must satisfy enum value set: [OR, AND] - This PR:
Value 'XOR' at 'conditionalOperator' failed to satisfy constraint: Member must satisfy enum value set: [AND, OR] - main: the DynamoDB text with
[AND, OR]
Query, ComparisonOperator of entry a null, "ConditionalOperator": "XOR":
- DynamoDB:
2 validation errors detected: Value null at 'queryFilter.a.member.comparisonOperator' failed to satisfy constraint: Member must not be null; Value 'XOR' at 'conditionalOperator' failed to satisfy constraint: Member must satisfy enum value set: [OR, AND] - This PR: the bare clause with
[AND, OR]
The same holds for {"X":"1"} or {} in ExpressionAttributeValues, ScanFilter and ExclusiveStartKey (10 shapes), for an AttributeValue with two datatypes or a null member, and for Limit 0, AttributesToGet [] or an invalid ReturnConsumedCapacity next to the faulty filter. 20 of the 44 XOR shapes in the second-fault probe answer in the counted form. Where main had the prefix right, this change removes it. Where main had only the list order wrong, the text now differs in both.
serde stops at the first error, so this path cannot produce the count or the second clause. Either state this as the single-fault form here, in the PR body and in the docstring of tests/test_conditional_operator_text.py, and file the combined form with #978, or cover it in this PR.
There was a problem hiding this comment.
I measured your rows again in us-east-1, each twice, on a table that does not exist, and got your answers on Query and Scan. The clause comes alone with [AND, OR] when both filter conditions are a valid EQ. Beside an empty AttributeValue or a null ComparisonOperator, the service sends the counted form with [OR, AND]. I took the first of your two options, in f8e9427. The doc of query_scan_deserialize_error, the module doc of conditional_operator_tests.rs, the docstring of tests/test_conditional_operator_text.py and the description now name the shapes where the service sends the counted form. They also say that this path does not send it. They name shapes instead of a one-fault rule, because the empty AttributeValue row reports one error and still gets the counted form. The combined form is on #978 with the rows, together with your {"S": 1} row, which I measured too.
| /// `Deserialize` impl writes. Measured 2026-11-13 and 2026-11-14 (us-east-1). | ||
| pub(crate) fn query_scan_deserialize_error(e: serde_json::Error) -> DynamoDbError { | ||
| match deserialize_error(e) { | ||
| DynamoDbError::ValidationException(msg) if msg.contains("at 'conditionalOperator'") => { |
There was a problem hiding this comment.
The match msg.contains("at 'conditionalOperator'") also matches text the client sent, because the message echoes the value. A direct call with the error of Select and the value x at 'conditionalOperator' returned Value 'x at 'conditionalOperator'' at 'select' ... with the prefix removed. No request reaches this today, since Query and Scan check Select and ReturnConsumedCapacity before from_value.
msg.starts_with("1 validation error detected: Value '") && msg.ends_with("' at 'conditionalOperator' failed to satisfy constraint: Member must satisfy enum value set: [AND, OR]") closes it at the same cost. With the guard removed entirely, all 872 engine tests still pass, so nothing pins it.
There was a problem hiding this comment.
Changed in f8e9427. The mapping now takes the envelope off only when the rest of the text starts with Value ' and ends with the ConditionalOperator clause's text after the value. That text is now the constant CONDITIONAL_OPERATOR_REFUSAL_END in extenddb-core, and the ConditionalOperator deserializer builds its message from it, so the deserializer and the mapping use one copy of the text. The new test query_scan_mapping_keeps_an_echo_of_conditional_operator pins it with your Select case. With the old contains guard put back, that test fails.
| /// invalid `ConditionalOperator`, answers `SerializationException`, the | ||
| /// exception DynamoDB sends (measured 2026-11-17, us-east-1). | ||
| #[tokio::test] | ||
| async fn unreadable_attributes_to_get_answers_before_conditional_operator() { |
There was a problem hiding this comment.
This test passes with the fix reverted. With query.rs and scan.rs back on crate::deserialize_error, refused_conditional_operator_text fails and this test stays green, on the plain and the preserve_order build. It writes ConditionalOperator last, the one order that passes on both builds.
With ConditionalOperator written first and "AttributesToGet": "x" after it, DynamoDB answers SerializationException Unexpected field type (twice, identical). The preserve_order build answers the ConditionalOperator ValidationException.
The comment on line 103 says the workspace build turns on preserve_order. cargo tree -p extenddb-engine -e features -i serde_json lists no preserve_order, and the SQLite binary (--features sqlite,dev-mode) does not have it. It comes in through bson, so it applies to the MongoDB build and to --workspace.
There was a problem hiding this comment.
You are right on both points. This test does not check the text change. refused_conditional_operator_text does, and it fails with the fix reverted. This one checks that the Query and Scan mapping keeps the exception a SerializationException, and its doc in f8e9427 says so. I also corrected the comment: bson turns on serde_json's preserve_order, so the MongoDB build and a --workspace build have it and the SQLite build does not. I measured your request with ConditionalOperator written first and "AttributesToGet": "x" after it, twice: the service answers SerializationException Unexpected field type, and the preserve_order build reads ConditionalOperator first and answers its refusal, as you found. That order dependence predates this PR and is #723, which the comment now names.
The Query and Scan mapping took "1 validation error detected: " off any ValidationException whose text held `at 'conditionalOperator'`. A refusal echoes the value the client sent, so the text of another member's refusal could match: a `Select` of `x at 'conditionalOperator'` lost its envelope in a direct call. The mapping now takes the envelope off only when the rest of the text is the ConditionalOperator clause: it starts with `Value '` and ends with the clause's text after the value. That text is the new `CONDITIONAL_OPERATOR_REFUSAL_END` in `extenddb-core`, which the `ConditionalOperator` deserializer uses too. The comments, the module docs and the wire test's docstring now state the scope of the bare clause. Beside some other faults, such as an empty AttributeValue or a null `ComparisonOperator` in the legacy filter, DynamoDB sends the clause inside a counted envelope with the set as `[OR, AND]`. Measured in us-east-1 on 24 Nov 2026, each request twice. serde stops at the first error, so this path does not send that form. #978 tracks it. A new unit test pins the guard: a Select refusal that echoes `conditionalOperator` keeps its envelope. It fails with the old guard. The comment in `unreadable_attributes_to_get_answers_before_conditional_operator` now says that bson turns on serde_json's preserve_order, so the MongoDB build and a `--workspace` build have it and the SQLite build does not (#723). The test's doc now says that it checks that the exception stays a SerializationException.
#544 moved the enum checks of handle_query into query_key_values::validate_query_request_body, which runs before typed deserialization. The merge takes that call from main and keeps this branch's query_scan_deserialize_error for the deserialization error.
hitesh96db
left a comment
There was a problem hiding this comment.
My required item is answered, and I have no open request on the code. Checked at 77143739 against DynamoDB in us-east-1, with builds of this head, the old head and current main.
Required item (the bare clause where DynamoDB sends the counted form with [OR, AND]): the author chose to state the scope in the docs and the PR body and to track the combined form on #978. That holds against the measurements. Of the 14 Query and Scan XOR shapes where DynamoDB sends the bare clause, this head matches 14 and so did the old head, and main matches 0. Of the 20 shapes where DynamoDB sends the counted form, none of the three builds matches. In 18 of those 20, main differed only by the set order, and this head now also lacks the 1 validation error detected: prefix. The 10 shapes where DynamoDB reports another fault first differ on all three builds. The PR states this.
Grid, 11305 cells (11246 stable on DynamoDB, 59 excluded as nondeterministic): 712 cells match DynamoDB that main got wrong, and none regresses against main. Against current main the PR changes 1882 cells, all Query or Scan, and each differs only by the removed prefix. The PR's 27 requests all match DynamoDB, and the 69 conditional-operator pytest tests pass.
Fixed or answered:
- The guard is anchored on
starts_with("Value '")andends_with(CONDITIONAL_OPERATOR_REFUSAL_END). Going back tocontains, or dropping theends_with, fails the new echo test. - The
AttributesToGettest still passes with the fix reverted, and its doc now says so. A mutant that turns every other error into aValidationExceptionfails it. - The
preserve_ordercomment is correct:cargo treeshows the feature on the MongoDB and--workspacebuilds and not on SQLite or PostgreSQL.
Optional: nothing pins starts_with("Value '"). Deleting that line keeps all three conditional-operator Rust tests passing, and I found no input where it changes the answer.
CI: only wasm fails, with E0308 in crates/core/src/metrics/* (std against web-time Instant). This PR does not touch those files, and an unrelated PR's WebAssembly run fails with the same error.
Not measured: PostgreSQL, MongoDB and Cassandra servers, and the preserve_order order dependence as a built binary.
What
Query and Scan now send the
ConditionalOperatorenum text without the1 validation error detected:prefix, as DynamoDB does on these two operations. For example,"ConditionalOperator": "XOR"getsValue 'XOR' at 'conditionalOperator' failed to satisfy constraint: Member must satisfy enum value set: [AND, OR]. The answer stays aValidationException. PutItem, UpdateItem and DeleteItem keep the prefix, as on DynamoDB.query_scan_deserialize_errorincrates/engine/src/lib.rstakes the error ofserde_json::from_valuefor Query and Scan. It passes the error todeserialize_erroras before. It removes the prefix only when the rest of the text is theConditionalOperatorclause. That text starts withValue 'and ends with the clause's text after the value. The checks keep their order. For example, anAttributesToGetstring written ahead of an invalidConditionalOperatorstill answersSerializationException, the exception DynamoDB sends. The clause's text after the value is in one place,CONDITIONAL_OPERATOR_REFUSAL_ENDincrates/core/src/types/item.rs, which theDeserializeimpl ofConditionalOperatoruses to build its message.Beside some other faults, DynamoDB sends the clause inside the
1 validation error detected:or2 validation errors detected:envelope, with the set as[OR, AND]. Two such faults are an empty AttributeValue and a nullComparisonOperatorin the legacy filter. serde stops at the first error, so this path does not send that form. #978 has these rows.Why
These are DynamoDB's answers, measured in us-east-1. I measured the two rows of the issue on 13 and 14 November 2026, and each request went out four times with the same answer. On 17 November 2026 the 27 requests of the new wire file went out once each and got the same answers. The
AttributesToGetrequests went out twice each on that day, and again on 24 November withConditionalOperatorwritten first. On 24 November the rows with a second fault went out twice each, on Query and Scan. Before this change, Query and Scan sent the text with the prefix.Closes #1049
Testing done
cargo test -p extenddb-engine --lib: 872 passed. Abackup::teststiming test failed once under load (Test a_retry_waits_on_its_registration_and_another_backup_is_refused fails when the first restore finishes before the third request #908, Flaky: a_retry_waits_on_its_registration_and_another_backup_is_refused gets TableAlreadyExistsException #951) and passed when run alone.--features serde_json/preserve_order: 872 passed. bson turns that feature on, so the MongoDB build and a--workspacebuild read members in the order written, and the SQLite build does not.cargo +1.97.0 clippy -p extenddb-engine --all-targets -- -D warnings, also with--features backup-test-hooks, andcargo fmt --checkare clean.tests/test_conditional_operator_text.pypassed 27 tests,tests/test_conditional_operator.pypassed 42 andtests/test_query_scan.pypassed 116. The new file holds the 27 measured requests.Line counts over main after the merge, with the lines after
#[cfg(test)]counted as tests: production +41 -10, tests +236.Changes since the 24 November review
ConditionalOperatorclause only. Before it, aValidationExceptionwhose text heldat 'conditionalOperator'lost its prefix, and a refusal echoes the value the client sent. The new testquery_scan_mapping_keeps_an_echo_of_conditional_operatorpins the guard with aSelectrefusal that echoesconditionalOperator. The test fails with the old guard. The commit also states the scope of the bare clause in the comments, the test docs and this description. The comment on serde_json's preserve_order now names the builds that have it.cargo test -p extenddb-core --libpassed 1161 tests.cargo test -p extenddb-engine --libpassed 891 of 893: twobackup::teststiming tests failed under load and passed when run alone, 3 times each.cargo test -p extenddb-wasm-adapterpassed its 3 unit tests and the parity corpus.-D warningson core and the engine, andcargo +1.91.1 checkof both, are clean.refused_conditional_operator_textfails too.handle_queryintoquery_key_values::validate_query_request_body. The merge takes that call from main and keeps this PR'squery_scan_deserialize_error. At the merge, fmt, a workspace check of all targets, engine clippy with-D warningsand an engine build without default features are clean. The engine's 936 unit tests pass, as do the WebAssembly adapter's 3 tests and its parity corpus. Line counts stay the same.Other open PRs:
serde_json::from_valuecalls. Each one conflicts with this PR inquery.rsorscan.rs. The resolution takes the PR's side and maps itsfrom_valueerror throughcrate::query_scan_deserialize_error.ConditionalOperatorclause to the combined message that fix(query): check Query values against the key schema and the number rules #544 builds before Query reads the request body.This PR keeps ExtendDB's order of the checks. #1098 lists seven requests where DynamoDB reports another fault first.
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
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.