Repository navigation
fix(core): answer JSON null members as DynamoDB does - #1103
LeeroyHannigan wants to merge 2 commits into
Conversation
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.
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
left a comment
There was a problem hiding this comment.
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.
What
ExtendDB now answers three JSON
nullmembers as DynamoDB does."ReturnConsumedCapacity": nullas a request without the member, on PutItem, GetItem, DeleteItem, UpdateItem, Query, Scan, BatchGetItem, BatchWriteItem, TransactGetItems and TransactWriteItems. It serves the request with noConsumedCapacity."AttributesToGet": [null]getsValidationException: Empty attribute name.nullitem attribute getsValidationException: The supplied Item contains a null AttributeValue: <name> is null.The
Deserializeimpl ofReturnConsumedCapacity(crates/core/src/types/capacity.rs) reads anOption<String>, so one rule covers every input type that holds the member.crates/core/src/serde_helpers.rsadds two readers.deserialize_attributes_to_getrefuses anullelement of the ScanAttributesToGet.deserialize_itemreads the PutItem item with a map visitor. A value of the wrong JSON type anywhere in the item answersSerializationExceptionfirst, as on DynamoDB. Otherwise the firstnullor refused value in key order is the answer, so{"pk": {"S": "k1"}, "a": null, "b": {}}getsa is null, as on DynamoDB. The type check ischeck_parameter_types, which moves fromcrates/core/src/partiql/params.rstoserde_helpers.rsso 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) answersValidationExceptionfor the exact textEmpty 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": nullon them. The new wire file covers them too. SearchVectors reads the same type, so it now also reads anullReturnConsumedCapacityas 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. Abackup::teststiming test failed once under load and passed when run alone.cargo +1.97.0 clippy --all-targets -- -D warningsonextenddb-core(also with--no-default-features) and onextenddb-engine(also with--features backup-test-hooks), andcargo fmt --check, are clean.tests/test_json_null_members.pyand four wire files on items, attribute values, batches and transactions passed 378 tests. For the six rows that DynamoDB answers withSerializationException, 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)."ReturnConsumedCapacity": null.Line counts, with the lines after
#[cfg(test)]counted as tests: production +217 -105, of which 93 lines movecheck_parameter_types, and tests +265.76a3045 merges main at 5252eda. #544 moved
has_equal_numbersandNUMBER_SET_DUPLICATESfromparams.rstovalidation::number. After the merge,params.rsuses neither main's base64 imports nor this PR'sHashSetimport, so the merge drops both. The merge passes fmt and a workspace check of all targets. Clippy with-D warningson 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:
deserialize_error, so they conflict with this PR input_item.rs. The PR that merges second adds|| msg.starts_with(extenddb_core::serde_helpers::NULL_MEMBER)todeserialize_error.check_parameter_typesfrompartiql/params.rstoserde_helpers.rs, and fix(core): refuse a null element of an L or a null member of an M #1437 adds the sameNULL_MEMBERandnull_memberto it. Whichever lands later keeps one copy, as fix(server): read request members in the client's order on every build #781 and fix(core): refuse a null element of an L or a null member of an M #1437 describe.partiql/params.rsthat this PR moves toserde_helpers.rs. Once this PR merges, each edit belongs inserde_helpers.rs.KNOWN_DESCRIPTORStoserde_helpers.rs, a list equal toTYPES. With this PR, both lists sit inserde_helpers.rs, and only one should stay.params.rschange, now on main. On a rebase, take this PR'suselines.DynamoDB answers a
nullin 15 other members withValidationException, and this PR does not change them. #1102 lists them:AttributesToGeton GetItem, Query and BatchGetItem, keys,ExpressionAttributeValues, and the items of BatchWriteItem and TransactWriteItems.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.