Repository navigation
fix(core): ignore the members DynamoDB ignores in an AttributeValue - #1377
LeeroyHannigan wants to merge 1 commit into
Conversation
DynamoDB ignores a member of a value object whose name is no type
descriptor, and a type descriptor whose payload is JSON null. It then
counts the descriptors left. None is "Supplied AttributeValue is empty,
must contain exactly one of the supported datatypes". Two or more are
"Supplied AttributeValue has more than one datatypes set, must contain
exactly one of the supported datatypes". One is read as that type. The
rule holds at the top level, in an L element and in an M value.
Measured on 2026-11-23 in us-east-1 through Query, PutItem and GetItem,
each request twice. {"S": "a", "X": "1"} and {"S": null, "N": "1"}
pass. {"X": "1"}, {"S": null} and {"S": null, "N": null} are empty.
ExtendDB refused any second member with the more than one datatypes
text. It refused an unknown descriptor alone with a
SerializationException, and a descriptor of JSON null alone with serde's
text for the payload.
One function now finds the member that gives a value its type,
type_descriptor in attribute_value.rs. It returns the one member
is_type_descriptor passes, in any member order, or the empty or the
more than one datatypes text. The deserializer calls it in from_members,
which visit_map and from_nested share, so the rule holds at every level.
The ExpressionAttributeValues check wraps every value with no descriptor
left, as it wrapped {}. The PartiQL parameter checks call the same
function, and parse_parameters no longer strips the ignored members
before the deserializer, which ignores them itself.
The readers that read a value before the deserializer does call the
same function too. The dynamodb:LeadingKeys reader and the per partition
throttling key took the first member of the value object. They now read
the member the engine reads, in any member order. A key with no
descriptor left or with two binds no LeadingKeys, and the engine refuses
that request before it reads or writes an item.
Two readers of stored and imported lines use the same deserializer. The
backup data file reader now reads {"S": "0", "X": "A"} as the S value 0,
where it refused the line. The writer emits one member per value, so no
written file reads otherwise, and the format docs state the rule. The
ImportTable reader for DYNAMODB_JSON now imports such a line. DynamoDB's
ImportTable answer for a line with an ignored member was not measured.
Fixes #629.
Fixes #980.
Fixes #1188.
demohan
left a comment
There was a problem hiding this comment.
Members the service ignores are ignored at bf86b70, and no answer moved away from the service. Across 478 shapes and places, sent twice, this head matches us-east-1 on 332 (main-bin 98), and merged onto main at 222d80a on 353 (current main 131), with SQLite and PostgreSQL giving the same answer every time and no case worse than main on 1014 and 1122 requests. Ignored members are dropped from the stored item and its size (a 450 KB ignored member costs 1.0 capacity unit, as on the service), the duplicate key checks and conditions on disguised keys match, and under a LeadingKeys policy fenced to alice, 78 disguised bob keys across 13 operations were refused on both backends with the bob item unchanged. Eight mutations of the fix each fail the new tests, fmt, both clippy commands and the 1.91.1 check are clean, CI is green on 64 of 64, and the merge builds and passes the core, engine and server tests.
#629 is not closed by this yet: its nested UpdateItem and TransactWriteItems cases still answer without the service's wrapper (below).
I will approve once an ExpressionAttributeValues value with no descriptor at any depth, and one whose number fails beside an ignored member, answer with the wrapper the service gives.
| // An AttributeValue with no type descriptor: `{}`, or members the | ||
| // deserializer ignores only. Caught here so the error names its | ||
| // key. Only the empty case is prefixed here. | ||
| if value.as_object().is_some_and(|members| { |
There was a problem hiding this comment.
This looks at the value's top-level members only. With :v set to {"L":[{"X":"1"}]}, {"M":{"k":{"X":1}}}, {"M":{"k":{"S":null}}}, {"M":{"k":{"S":null,"N":null}}} or {"L":[{"L":[{"X":"1"}]}]}, the service answers ExpressionAttributeValues contains invalid value: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes for key :v on UpdateItem, Query and a TransactWriteItems ConditionCheck, twice each; this head and the merge answer the bare Supplied AttributeValue is empty, .... That nested UpdateItem case is the one #629 reports. Wrapping a value error found at any depth would match.
| (r#"{"S":null,"N":null}"#, empty.clone()), | ||
| ("{}", empty.clone()), | ||
| // The number is read here and refused by the validation layer. | ||
| (r#"{"N":"bob","X":"1"}"#, n("bob")), |
There was a problem hiding this comment.
With an ignored member or a null descriptor beside "N":"bob" in an ExpressionAttributeValues value, in SET or a ConditionExpression and in both member orders, the service answers ExpressionAttributeValues contains invalid value: The parameter cannot be converted to a numeric value: bob for key :z, while {"N":"bob"} alone gets 1 validation error detected: .... This head gives the 1 validation error detected form for all of them; main gave the more-than-one-datatypes text, so this is not a regression.
| //! this format leaves alone, so a repeated name inside an `M` is last-wins); | ||
| //! a repeated type descriptor at the top of an attribute value | ||
| //! the deserializer ignores a member whose name is no type descriptor and a | ||
| //! descriptor of JSON null, as the request path does, so `{"S":"0","X":"A"}` |
There was a problem hiding this comment.
The request path refuses {"S":"x","S":null} as empty, since the later member wins when the body is parsed; only this reader reads it as S("x"), and the service refuses a repeated key with SerializationException: Duplicate key found in payload (#630). No test reads an ignored member through this reader or ImportTable, though both changed; a probe shows the reader does what the comment says for {"S":"0","X":"A"}.
|
|
||
| /// The value the members of one object describe, at any level: the one | ||
| /// member [`type_descriptor`] leaves, read by [`from_descriptor`]. The | ||
| /// payload is read after the count. |
There was a problem hiding this comment.
Optional. The service reads each descriptor's payload before it counts them: {"S":"v","N":"bob"} gets the numeric text, {"S":"v","NULL":false} the NULL text and {"S":"v","N":5} a SerializationException, where this head and main give the more-than-one-datatypes text. Not a regression, but "the payload is read after the count" states the other order as the rule. docs/design/03-component-core.md:118 still says a value with zero or several keys is refused, which REQ-TYPE-001 now qualifies. After the merge, the UNKNOWN_TYPE_DESCRIPTOR arm in engine/src/query_key_values.rs:233-248 (on main since #544, not #1260's branch as the body says) can no longer match.
What
ExtendDB now reads an AttributeValue as DynamoDB reads it. It ignores a member whose name is no type descriptor, and a type descriptor whose payload is JSON null. Then it counts the descriptors left:
Supplied AttributeValue is empty, must contain exactly one of the supported datatypesSupplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypesThe rule holds at the top level, in an
Lelement and in anMvalue.The changes:
type_descriptorincrates/core/src/types/attribute_value.rsfinds the one member that gives a value its type, besideis_type_descriptor. It gives the same member in any member order. So a build that keeps the request's member order reads the same value as a build that sorts the members.from_members, whichvisit_mapandfrom_nestedshare.check_valueincrates/core/src/partiql/params.rs) call it in place of their own copy of the rule.parse_parametersno longer strips the ignored members first, because the deserializer ignores them itself.dynamodb:LeadingKeysreader (extract_typed_valueincrates/server/src/leading_keys.rs) and the per partition throttling key (extract_partition_valueincrates/server/src/throttle_helpers.rs) took the first member of a value object. They now calltype_descriptor, so they read the member the engine reads. A key with no descriptor left or with two binds nodynamodb:LeadingKeys, and the engine refuses that request before it reads or writes an item.ExpressionAttributeValuescheck wraps every value with no descriptor left, as it wrapped{}.docs/design/01-requirements.mdand the reader contract incrates/core/src/backup_format/data_file.rsstate the rule.Two readers of stored and imported lines use the same deserializer:
{"S": "0", "X": "A"}as the S value0, where it refused the line. The writer emits one member per value, so no written file reads otherwise.DYNAMODB_JSONnow imports such a line. DynamoDB's ImportTable answer for a line with an ignored member was not measured. ImportTable: DynamoDB's answer for a DYNAMODB_JSON line with a member that is no type descriptor is not measured #1378 holds that measurement.Fixes #629
Fixes #980
Fixes #1188
Why
DynamoDB was measured in us-east-1 on 23 November 2026, on a table that does not exist. Each request went out twice and got the same answer both times. Q is a Query with the shape as an unused
:z. F is a Query whose FilterExpression reads:z. P is a PutItem with the shape as the attributea. G is a GetItem with the shape as the key. In Q and F the empty and the more than one datatypes texts come asExpressionAttributeValues contains invalid value: <text> for key :z. In P and G they are bare. A shape that passes getsResourceNotFoundExceptionin F, P and G, and the unused value text in Q.{"S": "a", "X": "1"},{"X": "1", "S": "a"}{"S": null, "N": "1"},{"N": "1", "S": null},{"S": "a", "N": null, "X": "1"}{"NULL": true, "S": null},{"BOOL": false, "S": null}{"S": "a", "N": "1"}{"X": "1"}SerializationException,unknown AttributeValue type descriptor: X{"S": null}{"S": null, "X": "1"},{"S": null, "N": null}{}{"N": "bob", "X": "1"}The parameter cannot be converted to a numeric value: bobIn a PutItem item, an
Lelement and anMvalue follow the same rule.{"L": [{"S": "a", "X": "1"}]}passes,{"L": [{"X": "1"}]}is empty and{"L": [{"S": "a", "N": "1"}]}is more than one datatypes.Testing done
cargo test -p extenddb-core --lib --no-fail-fast: 1147 passed, 1 ignored, whichmainignores too.cargo test -p extenddb-engine --lib --no-fail-fast: 871 passed.cargo test -p extenddb-server --lib --no-fail-fast: 515 passed and 5 failed. The 5 arebackup_storespool privacy tests. On this host every parent directory of the spool belongs to another user, and the same 5 fail onmain.cargo +1.97.0 clippy -p extenddb-core -p extenddb-server -p extenddb-engine --all-targets -- -D warningsandcargo +1.97.0 fmt --all -- --checkare clean.mainand kept the tests. Then 6 core tests and 1 engine test failed.maingets 7 of them. Q6 and F6 ({"S": "a", "N": "1"}) get the bare more than one datatypes text, as onmain, where DynamoDB wraps it. The other 9 are Query rows that now reach checks this PR does not change. Query looks the table up before it checks the values (Query looks up the table, the index and ConsistentRead before it checks the expressions, and reads the key condition before the filter #1208), and it does not convert anNin the values (fix(query): check Query values against the key schema and the number rules #544 adds that).{"S": "v", "X": "1"}asastoredaas{"S": "v"}. The Query rows of A value with a null payload beside another type descriptor is read as that type by DynamoDB and refused by ExtendDB #1188 got HTTP 200.dynamodb:LeadingKeysto one partition. It sent the key of another partition as{"A": "<allowed>", "S": "<other>"}, with the members in both orders, and as{"N": null, "S": "<other>"}. The requests went through 20 operations: the item operations, the batch and transaction operations, and Query withKeyConditionExpressionand withKeyConditions. PartiQL SELECT, UPDATE, DELETE, INSERT, BatchExecuteStatement and ExecuteTransaction were among them too. The server refused all 60 requests withAccessDeniedException. The item of the other partition stayed as it was after the 39 write requests.mainand on this PR, with the same output.type_descriptorthe members in both orders.Production is +101 -95 and the tests are +236 -122.
Conflicts that this PR adds, with their resolutions:
attribute_value.rsintoattribute_value/tests.rs. Carry four test edits into the moved file: the table that replacesunknown_type_descriptor_rejected, theQrow and the deleted second table ofnested_error_text_is_unchanged, andtype_descriptor_is_the_one_counted_member_in_either_order.TYPES,check_typesandtyped_membersfromparams.rsintoserde_helpers.rs. On top of theirs,typed_membersfilters withis_type_descriptor,TYPESgoes,modelled_valueand its one caller go, andcheck_valuecallstype_descriptor.shape_fault_firstincrates/engine/src/query_key_values.rs, on the branch of #1260 and the PRs under it, matches the textunknown AttributeValue type descriptor. This PR deletes that text, so that arm and its constant can go when that branch rebases. The empty text falls to the same check.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.