Skip to content

fix(engine): send the ConditionalOperator enum text alone on Query and Scan - #1100

Open
LeeroyHannigan wants to merge 4 commits into
mainfrom
fix/1049-conditional-operator-text
Open

LeeroyHannigan wants to merge 4 commits into
mainfrom
fix/1049-conditional-operator-text

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

What

Query and Scan now send the ConditionalOperator enum text without the 1 validation error detected: prefix, as DynamoDB does on these two operations. For example, "ConditionalOperator": "XOR" gets Value 'XOR' at 'conditionalOperator' failed to satisfy constraint: Member must satisfy enum value set: [AND, OR]. The answer stays a ValidationException. PutItem, UpdateItem and DeleteItem keep the prefix, as on DynamoDB.

query_scan_deserialize_error in crates/engine/src/lib.rs takes the error of serde_json::from_value for Query and Scan. It passes the error to deserialize_error as before. It removes the prefix only when the rest of the text is the ConditionalOperator clause. That text starts with Value ' and ends with the clause's text after the value. The checks keep their order. For example, an AttributesToGet string written ahead of an invalid ConditionalOperator still answers SerializationException, the exception DynamoDB sends. The clause's text after the value is in one place, CONDITIONAL_OPERATOR_REFUSAL_END in crates/core/src/types/item.rs, which the Deserialize impl of ConditionalOperator uses to build its message.

Beside some other faults, DynamoDB sends the clause inside the 1 validation error detected: or 2 validation errors detected: envelope, with the set as [OR, AND]. Two such faults are an empty AttributeValue and a null ComparisonOperator in 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 AttributesToGet requests went out twice each on that day, and again on 24 November with ConditionalOperator written 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

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

  • f03b1a3 merges main at 3534c9e, with no conflict.
  • f8e9427 takes the prefix off the ConditionalOperator clause only. Before it, a ValidationException whose text held at 'conditionalOperator' lost its prefix, and a refusal echoes the value the client sent. The new test query_scan_mapping_keeps_an_echo_of_conditional_operator pins the guard with a Select refusal that echoes conditionalOperator. 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.
  • After both commits:
    • cargo test -p extenddb-core --lib passed 1161 tests. cargo test -p extenddb-engine --lib passed 891 of 893: two backup::tests timing tests failed under load and passed when run alone, 3 times each.
    • cargo test -p extenddb-wasm-adapter passed its 3 unit tests and the parity corpus.
    • Clippy with -D warnings on core and the engine, and cargo +1.91.1 check of both, are clean.
    • With the mapping turned off, refused_conditional_operator_text fails too.
  • 7714373 merges main at 5252eda. fix(query): check Query values against the key schema and the number rules #544 moved the enum checks of handle_query into query_key_values::validate_query_request_body. The merge takes that call from main and keeps this PR's query_scan_deserialize_error. At the merge, fmt, a workspace check of all targets, engine clippy with -D warnings and 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:

This PR keeps ExtendDB's order of the checks. #1098 lists seven requests where DynamoDB reports another fault first.

Checklist

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

ADR / RFC: n/a


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.

…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 hitesh96db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread crates/engine/src/lib.rs Outdated
}

/// [`deserialize_error`] for Query and Scan, which send a refused
/// `ConditionalOperator` as the enum clause alone. PutItem, UpdateItem and

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Comment thread crates/engine/src/lib.rs Outdated
/// `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'") => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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 hitesh96db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 '") and ends_with(CONDITIONAL_OPERATOR_REFUSAL_END). Going back to contains, or dropping the ends_with, fails the new echo test.
  • The AttributesToGet test still passes with the fix reverted, and its doc now says so. A mutant that turns every other error into a ValidationException fails it.
  • The preserve_order comment is correct: cargo tree shows the feature on the MongoDB and --workspace builds 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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Query and Scan put the 1 validation error detected: prefix on an invalid ConditionalOperator, and DynamoDB sends the text without it

2 participants