Skip to content

fix(core): refuse a null element of an L or a null member of an M - #1437

Open
LeeroyHannigan wants to merge 1 commit into
fix/1404-payloads-before-countfrom
fix/1432-null-members
Open

LeeroyHannigan wants to merge 1 commit into
fix/1404-payloads-before-countfrom
fix/1432-null-members

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

What

A JSON null as an element of an L or a member of an M now gets DynamoDB's ValidationException, The supplied Item contains a null AttributeValue. For a member of an M, : <name> is null follows the text. Before this change, the null went to serde_json, and ExtendDB sent a SerializationException with serde's invalid type: null text.

DynamoDB gives the text in a form that depends on the reader of the value:

  • In a key, an item, AttributeUpdates, Expected and ScanFilter, the text is bare.
  • In an ExpressionAttributeValues value, the text comes inside ExpressionAttributeValues contains invalid value: <text> for key :v.
  • In ExclusiveStartKey, The provided starting key is invalid: comes before the text.

ExtendDB now gives the first two forms. In ExclusiveStartKey it gives the bare text (see below).

A value of the wrong JSON type written after the null, in the same L or M, comes first. It gets a SerializationException, as in DynamoDB, with ExtendDB's text for that type.

The code:

  • crates/core/src/serde_helpers.rs: NULL_MEMBER and null_member(name) hold the null text and its named form. fix(core): answer JSON null members as DynamoDB does #1103 adds the same two items with the same lines. The ExpressionAttributeValues reader wraps a null element or member as it wraps a value with no single type descriptor. is_serialization_text also matches <descriptor> member must be, the text of a set member of the wrong JSON type, so that text stays bare.
  • crates/core/src/types/attribute_value.rs: the L and M arms of from_descriptor refuse a null with the text. On a null, ahead_of_null checks the elements or members after it with the existing parameter type check (check_parameter_types). It returns the first type fault, or else the null text.
  • crates/core/src/partiql/params.rs: the PartiQL parameter check uses the two shared items.
  • The measured rows are in the existing tables of nested_error_text and values_with_no_single_descriptor_are_refused_by_key. Two rows in tests/test_attribute_value_validation.py send a null element and a null member through each reader of the file.

The base of this PR is #1418.

Why

DynamoDB was measured in us-east-1 on 24 November 2026 on the table ets-parity1185-missing, which does not exist. Each request went out twice, with the same answer both times. NULL stands for The supplied Item contains a null AttributeValue. P rows send the value as the PutItem attribute a. U rows send it as :v in an UpdateItem SET a = :v, where DynamoDB wraps the text for :v. SER stands for a SerializationException.

Value DynamoDB ExtendDB at the base
{"L": [null]} NULL SER, invalid type: null
{"M": {"b": null}} NULL : b is null SER, invalid type: null
{"M": {"a": {"L": [null]}}} NULL SER, invalid type: null
{"L": [{"M": {"b": null}}]} NULL : b is null SER, invalid type: null
{"L": [null, {}]} NULL SER, invalid type: null
{"L": [null, {"SS": ["a", null]}]} NULL SER, invalid type: null
{"L": [null, {"S": 1}]} SER, NUMBER_VALUE cannot be converted to String SER, invalid type: null
{"M": {"a": null, "b": "x"}} SER, Unexpected value type in payload SER, invalid type: null

The measurements also sent the null element and the null member through each reader of a value:

  • :v in Query, Scan, DeleteItem, PutItem conditions and a TransactWriteItems Update.
  • A GetItem key, and the items of BatchWriteItem and TransactWriteItems.
  • AttributeUpdates, an Expected value and its AttributeValueList, and a ScanFilter AttributeValueList.

With this PR, the null rows get DynamoDB's exception and text. The rows with a wrong JSON type after the null get DynamoDB's exception type, with ExtendDB's texts for a wrong JSON type (#1012).

Testing done

  • cargo test -p extenddb-core --lib --no-fail-fast: 1149 passed, 1 ignored. cargo test -p extenddb-engine --lib --no-fail-fast: 871 passed. cargo +1.97.0 clippy -p extenddb-core --all-targets -- -D warnings and cargo +1.97.0 fmt --all -- --check are clean. The last change touches only crates/core.
  • A control restored the base's L and M arms and has_no_single_descriptor, and kept the new tables. Both tables failed on their first null row. A second control removed ahead_of_null. Both tables then failed on {"L":[null,{"S":1}]}.
  • The measured requests went to a SQLite release build of the change before the last: the rows above and the readers. The other 323 measured requests of fix(core): check every payload of a two descriptor value before the count #1418 got the same answers as on the base. Against that build, six pytest files of tests/ that send attribute values gave 378 passed and 1 xfailed. The last change adds table rows and writes is_serialization_text with the same matches.

Over the base, production adds 85 lines and removes 34. The tests add 155 lines and remove 18.

The measured rows that still differ from DynamoDB:

Conflicts:

Closes #1432

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.

A JSON null inside an L or an M went to serde_json::from_value, whose text the engine answered with a SerializationException. DynamoDB answers a ValidationException with the text "The supplied Item contains a null AttributeValue". For a member of an M, ": <name> is null" follows it. In UpdateItem the text of a :v value comes inside "ExpressionAttributeValues contains invalid value: <text> for key :v". A value of the wrong JSON type written after the null in the same value comes first, as a SerializationException. Measured in us-east-1 on 24 November 2026 on a table that does not exist, each request twice.

The null text and its named form move to serde_helpers as a constant and a helper. The PartiQL parameter check and the L and M arms of from_descriptor share them, and #1103 adds the same two items. When an element or member is null, from_descriptor checks the JSON types of the ones after it with the parameter type check. It returns the first type fault, else the null text. The ExpressionAttributeValues deserializer names the key around a null element or member as it does around a value with no single type descriptor. A set member of the wrong JSON type stays bare there. The engine already classifies the texts.

Tests: the measured rows in the attribute value and ExpressionAttributeValues tables, and two rows in the Python validation table that cover every reader.

Closes #1432

@demohan demohan 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.

A JSON null element of an L or member of an M is refused with the service's text at 96301d2. Of 422 shapes sent twice to us-east-1 and to this head, its base and main on SQLite and PostgreSQL, covering every reader (Item, Key, ExpressionAttributeValues, ExclusiveStartKey, batch and transaction members, PartiQL parameters), the backends agree everywhere, this head matches the service's error class on 360 of the first 364 where the base matches the full text on 73 and main on 64, and no shape the base or main answered as the service does is answered otherwise here. The service reads an M in key order, as this head does. Main refused every null shape and stores {"NULL":true}, never a JSON null, so no stored item holds one; items with NULL values written by main were read, updated and deleted on this head merged onto main. Seven of eight controls fail the new tables, the new pytest rows fail on the base and pass here, fmt, clippy, the 1.91.1 check and 1149 core tests are clean, CI is green on 59 of 59, and it merges onto main at 222d80a without conflict and builds and passes the 1.94.0 check and the tests there.

I will approve once a null past the nesting limit gets the service's nesting answer.

let mut rest = arr.into_iter();
while let Some(v) = rest.next() {
let read = match v {
Value::Null => Err(NULL_MEMBER.to_owned()),

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.

This refuses the null before checking depth, here and in the M arm at line 282. An item attribute with a null inside 32 lists, or inside 32 maps, gets Nesting Levels have exceeded supported limits: ... from the service, and a 33-list :v the wrapped nesting text; this head gives the null text for all of them on both backends. The base answered SerializationException, so this is not a regression. The PartiQL parameter walk already checks depth first (params.rs:238 and :247, enter(depth)?), and the same on this branch, with 32-list, 32-map and 33-list :v rows, would match; the body's 33 lists is 32 for an item attribute.

if !refusal.starts_with(NULL_MEMBER) {
return refusal;
}
rest.filter(|v| !v.is_null())

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.

Optional. With rest.filter(|v| !v.is_null()) removed all 1149 core tests pass, so no row has two nulls in one L or M; the service answers {"L":[null,null]} with the null text and {"M":{"b":null,"a":null}} with a is null, and this head matches both. The doc above (lines 297-304), the arm comment and the body say "written after the null", but a type fault anywhere in the L or M comes first, and an M is read in key order.

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.

2 participants