Repository navigation
fix(core): refuse a null element of an L or a null member of an M - #1437
LeeroyHannigan wants to merge 1 commit into
Conversation
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
left a comment
There was a problem hiding this comment.
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()), |
There was a problem hiding this comment.
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()) |
There was a problem hiding this comment.
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.
What
A JSON null as an element of an
Lor a member of anMnow gets DynamoDB's ValidationException,The supplied Item contains a null AttributeValue. For a member of anM,: <name> is nullfollows the text. Before this change, the null went to serde_json, and ExtendDB sent a SerializationException with serde'sinvalid type: nulltext.DynamoDB gives the text in a form that depends on the reader of the value:
AttributeUpdates,ExpectedandScanFilter, the text is bare.ExpressionAttributeValuesvalue, the text comes insideExpressionAttributeValues contains invalid value: <text> for key :v.ExclusiveStartKey,The provided starting key is invalid:comes before the text.ExtendDB now gives the first two forms. In
ExclusiveStartKeyit gives the bare text (see below).A value of the wrong JSON type written after the null, in the same
LorM, 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_MEMBERandnull_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. TheExpressionAttributeValuesreader wraps a null element or member as it wraps a value with no single type descriptor.is_serialization_textalso 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: theLandMarms offrom_descriptorrefuse a null with the text. On a null,ahead_of_nullchecks 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.nested_error_textandvalues_with_no_single_descriptor_are_refused_by_key. Two rows intests/test_attribute_value_validation.pysend 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 forThe supplied Item contains a null AttributeValue. P rows send the value as the PutItem attributea. U rows send it as:vin an UpdateItemSET a = :v, where DynamoDB wraps the text for:v. SER stands for a SerializationException.{"L": [null]}invalid type: null{"M": {"b": null}}: b is nullinvalid type: null{"M": {"a": {"L": [null]}}}invalid type: null{"L": [{"M": {"b": null}}]}: b is nullinvalid type: null{"L": [null, {}]}invalid type: null{"L": [null, {"SS": ["a", null]}]}invalid type: null{"L": [null, {"S": 1}]}NUMBER_VALUE cannot be converted to Stringinvalid type: null{"M": {"a": null, "b": "x"}}Unexpected value type in payloadinvalid type: nullThe measurements also sent the null element and the null member through each reader of a value:
:vin Query, Scan, DeleteItem, PutItem conditions and a TransactWriteItems Update.AttributeUpdates, anExpectedvalue and itsAttributeValueList, and aScanFilterAttributeValueList.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 warningsandcargo +1.97.0 fmt --all -- --checkare clean. The last change touches onlycrates/core.LandMarms andhas_no_single_descriptor, and kept the new tables. Both tables failed on their first null row. A second control removedahead_of_null. Both tables then failed on{"L":[null,{"S":1}]}.tests/that send attribute values gave 378 passed and 1 xfailed. The last change adds table rows and writesis_serialization_textwith 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:
ExpressionAttributeValuesvalues first. In a merge of this branch with fix(core): answer JSON null members as DynamoDB does #1103, the deserializer answers the PutItem row withS value must be a string, a text that ExtendDB sends as a SerializationException. Merge this PR after fix(server): read request members in the client's order on every build #781 and fix(core): answer JSON null members as DynamoDB does #1103.BOOLpayload given as a string after a null, such as{"L": [null, {"BOOL": "yes"}]}. DynamoDB reads the stringsyesandtrueas aBOOL(AttributeValue: DynamoDB reads the strings true, false, yes and no as a BOOL payload, where ExtendDB refuses them #1424) and answers NULL. The parameter type check refuses them, so ExtendDB answersBOOL value must be a boolean.LorMpayload holds a wrong JSON type, such as{"S": "x", "L": [{"S": 1}]}, with or without a null. ExtendDB answers the descriptor count, where DynamoDB gives the SerializationException. The base's two descriptor check leaves these payloads to the deserializer (PutItem answers ValidationException for a set member or list element of the wrong JSON type, where DynamoDB answers SerializationException #1104).{"L": [{"N": "bob"}, null]}: NULL, where DynamoDB refuses the number first.ExclusiveStartKey, the prefixThe provided starting key is invalid:is missing. fix(scan): check AttributesToGet, ScanFilter, ExclusiveStartKey and ExpressionAttributeValues in the service's order #854 changes the function that adds it.NSor aBSgets the text for a value with no type. No set's text gets the:vwrapper (A null set member gets the empty value text in an NS or a BS and no :v wrapper, where DynamoDB names the set #1438).Conflicts:
params.rs, keep fix(core): answer JSON null members as DynamoDB does #1103'suselines. Inserde_helpers.rs, git keeps two copies ofNULL_MEMBERandnull_member. Remove the second copy. The other conflicts are those of the base, and fix(core): check every payload of a two descriptor value before the count #1418 gives their resolution. With both resolutions, the merged tree builds, and the core tests pass.uselines ofparams.rs. Keep this PR'sserde_helpersline and the other PR'stypesline.attribute_value.rs,ahead_of_nulland fix(core): give a set with duplicate members DynamoDB's text #1368's helpers come at the same place. Keep both sides, and endahead_of_nullwith its closing brace before fix(core): give a set with duplicate members DynamoDB's text #1368's lines.Closes #1432
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.