Skip to content

fix(core): answer JSON null members as DynamoDB does - #1103

Open
LeeroyHannigan wants to merge 2 commits into
mainfrom
fix/1050-json-null-members
Open

LeeroyHannigan wants to merge 2 commits into
mainfrom
fix/1050-json-null-members

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

What

ExtendDB now answers three JSON null members as DynamoDB does.

  • ExtendDB reads "ReturnConsumedCapacity": null as a request without the member, on PutItem, GetItem, DeleteItem, UpdateItem, Query, Scan, BatchGetItem, BatchWriteItem, TransactGetItems and TransactWriteItems. It serves the request with no ConsumedCapacity.
  • A Scan with "AttributesToGet": [null] gets ValidationException: Empty attribute name.
  • A PutItem with a null item attribute gets ValidationException: The supplied Item contains a null AttributeValue: <name> is null.

The Deserialize impl of ReturnConsumedCapacity (crates/core/src/types/capacity.rs) reads an Option<String>, so one rule covers every input type that holds the member. crates/core/src/serde_helpers.rs adds two readers. deserialize_attributes_to_get refuses a null element of the Scan AttributesToGet. deserialize_item reads the PutItem item with a map visitor. A value of the wrong JSON type anywhere in the item answers SerializationException first, as on DynamoDB. Otherwise the first null or refused value in key order is the answer, so {"pk": {"S": "k1"}, "a": null, "b": {}} gets a is null, as on DynamoDB. The type check is check_parameter_types, which moves from crates/core/src/partiql/params.rs to serde_helpers.rs so that the item reader and the PartiQL parameters share one copy in every build. null_member(name) builds the null text for an item attribute and for a PartiQL parameter, so the text has one copy.

deserialize_error (crates/engine/src/lib.rs) answers ValidationException for the exact text Empty attribute name, and the PutItem error mapping (crates/engine/src/put_item.rs) does so for a text that starts with the null text. A request string that serde copies into its error text does not change the exception.

The issue's table lists ExecuteStatement, BatchExecuteStatement and ExecuteTransaction as refused, but origin/main already served "ReturnConsumedCapacity": null on them. The new wire file covers them too. SearchVectors reads the same type, so it now also reads a null ReturnConsumedCapacity as absent. DynamoDB's answer for SearchVectors is not measured.

Why

These are DynamoDB's answers, measured in us-east-1. The rows of the issue were measured on 14 November 2026. On 17 November 2026 the 23 requests of the new wire file went out again, twice each, with the same answer both times. Before this change, ExtendDB answered each of these members with SerializationException.

Closes #1050

Testing done

  • cargo test -p extenddb-core --lib: 1147 passed, 1 ignored. The same with --features serde_json/preserve_order, the key order of the workspace build: 1147 passed.
  • cargo test -p extenddb-engine --lib: 870 passed. A backup::tests timing test failed once under load and passed when run alone.
  • cargo +1.97.0 clippy --all-targets -- -D warnings on extenddb-core (also with --no-default-features) and on extenddb-engine (also with --features backup-test-hooks), and cargo fmt --check, are clean.
  • Against ExtendDB on SQLite, tests/test_json_null_members.py and four wire files on items, attribute values, batches and transactions passed 378 tests. For the six rows that DynamoDB answers with SerializationException, the wire file compares the exception only, because DynamoDB's text comes from its own JSON reader (A request member of the wrong JSON type gets serde_json's error text, where the service sends its own #1012).
  • With the change reverted, the Rust row test fails on the Scan row with "ReturnConsumedCapacity": null.
  • A release-mode timing test of the PutItem input read ran against origin/main in the same runs. For an item of 1,000 attributes it took 210.74 us against 209.05 us. For an item near 400 KB it took 14.97 us against 15.46 us. The order and the values of the item do not change.

Line counts, with the lines after #[cfg(test)] counted as tests: production +217 -105, of which 93 lines move check_parameter_types, and tests +265.

76a3045 merges main at 5252eda. #544 moved has_equal_numbers and NUMBER_SET_DUPLICATES from params.rs to validation::number. After the merge, params.rs uses neither main's base64 imports nor this PR's HashSet import, so the merge drops both. The merge passes fmt and a workspace check of all targets. Clippy with -D warnings on core and the engine, and an engine build without default features, are clean too. Core passed 1178 tests, with 1 ignored, and the engine 933. The WebAssembly adapter passed its 3 tests and the parity corpus. Line counts stay the same.

Other open PRs:

DynamoDB answers a null in 15 other members with ValidationException, and this PR does not change them. #1102 lists them: AttributesToGet on GetItem, Query and BatchGetItem, keys, ExpressionAttributeValues, and the items of BatchWriteItem and TransactWriteItems.

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.

Amazon DynamoDB reads "ReturnConsumedCapacity": null as a request
without the member. It serves the request and returns no
ConsumedCapacity. ExtendDB answered SerializationException on the ten
item, batch and transaction operations.

DynamoDB refuses a null AttributesToGet element on Scan with
ValidationException: Empty attribute name. It refuses a null attribute
of a PutItem item with ValidationException: The supplied Item contains
a null AttributeValue: <name> is null. ExtendDB answered
SerializationException for both.

DynamoDB refuses an item value of the wrong JSON type with
SerializationException, ahead of a null or empty value wherever each
stands. ExtendDB answered ValidationException when the empty value
came first.

Measured in us-east-1 on 14 Nov 2026, and on 17 Nov 2026 for item
attributes that are not the key. Each request went out twice.

The ReturnConsumedCapacity reader now takes a null as the default. It
is one rule for every input type that holds the member. Scan reads
AttributesToGet and PutItem reads its item through two new serde
helpers. After the first fault, the item reader checks the JSON types
of the remaining values with the PartiQL parameter type check. That
check moves to serde_helpers so that every build has it. The null item
text is shared with the PartiQL parameter checks.

Fixes #1050.
LeeroyHannigan added a commit that referenced this pull request Nov 19, 2026
The service checks the members of one ExpressionAttributeValues map in
the order that a Java HashMap of the map yields them. It checks one
PartiQL parameter map the same way. Two members in one bucket come in
the order written. The previous commit made every build walk these maps
in the order written. Main walks them in name order on the builds
without the MongoDB backend. Neither order is the service's, so the
previous commit changed answers that main gave correctly. For :c and :b
both {}, the service and main name :b, and the order written names :c.

The bucket model of the PartiQL echo moves from the engine to
extenddb_core::map_order. The echo, the PartiQL parameter checks and the
checks of ExpressionAttributeValues and ExpressionAttributeNames use it.
For two empty names, the service named either member in each order, so
any fixed order gives one of its answers.

The two placeholder maps also take the service's steps in its order.
The service refuses a value of the wrong JSON type first, the first one
written. It finds such a value while it reads the request. A JSON null
is not such a value. Then ExpressionAttributeValues checks its keys, and
then its values. ExpressionAttributeNames checks its empty names ahead
of its keys. The refusal of each fault keeps its text.

ExpressionAttributeValues uses check_types, the check that
check_parameter_types runs on each PartiQL parameter. A build without the
partiql feature has no PartiQL module, so both functions move from that
module to serde_helpers. PR #1103 makes the same move.

Measured in us-east-1 on 2026-11-12 and 2026-11-19, in both member
orders, on maps of two, three and four members (#1013).
#544 moved has_equal_numbers and NUMBER_SET_DUPLICATES from
partiql/params.rs to validation::number, and this branch moved
check_parameter_types to serde_helpers. After the merge, params.rs uses
neither the base64 imports from main nor the HashSet import from this
branch. The merge drops both.
@navareamol navareamol self-assigned this Nov 25, 2026

@navareamol navareamol left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think the item reader names the wrong attribute when an item holds two nulls. deserialize_item reads the serde_json::Value that handle_put_item parsed, and the server binary builds serde_json without preserve_order (only the MongoDB backend's bson dependency turns it on). So the visitor sees the attributes in name order, not in the order the request wrote them. I sent {"pk": {"S": "k1"}, "c": null, "ba": null} to a debug build of 76a3045 on SQLite and on PostgreSQL, and both answered The supplied Item contains a null AttributeValue: ba is null. The doc comment on deserialize_item says DynamoDB names c for this item. {"pk": {"S": "k1"}, "b": null, "a": null} answers a is null too. A MongoDB build has preserve_order on, so going by cargo tree -e features -i serde_json it would answer c for the same request (I did not run a MongoDB build). "The key order of the workspace build" in the description holds for cargo test --workspace, not for the postgres, sqlite or cassandra binaries. Every row in tests/test_json_null_members.py and json_null_tests.rs writes a before b, so neither test sees this. Could you add the c/ba row to the wire file, and then either read the PutItem item in the order the request wrote it or keep name order and say in the doc comment that it differs from DynamoDB? Has anyone checked whether DynamoDB names the first null as written, for example with {"b": null, "a": null}?

Minor: when the first refused value already has the wrong JSON type, first_type_fault replaces it with the next wrong-type value. For {"pk": {"S": "k1"}, "a": {"S": 1}, "b": "x"}, main answers S value must be a string and this head answers invalid type: string "x", expected a DynamoDB AttributeValue map with exactly one type descriptor. The exception is still SerializationException, so only the message moves to the second attribute. Running check_parameter_types on the faulting value before searching the rest would keep the first one, which is what the doc comment describes.

The wasm check fails with E0308 at crates/core/src/metrics/collector.rs:60, the same error main shows at 5252eda, so it does not come from this change.

I will approve once the two-null order has a test row and either matches the written order or is documented as a known difference.

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

2 participants