Skip to content

fix(core): ignore the members DynamoDB ignores in an AttributeValue - #1377

Open
LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/980-ignored-descriptors
Open

LeeroyHannigan wants to merge 1 commit into
mainfrom
fix/980-ignored-descriptors

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

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:

  • none: Supplied AttributeValue is empty, must contain exactly one of the supported datatypes
  • two or more: Supplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypes
  • one: ExtendDB reads the value as that type, as before.

The rule holds at the top level, in an L element and in an M value.

The changes:

  • type_descriptor in crates/core/src/types/attribute_value.rs finds the one member that gives a value its type, beside is_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.
  • The deserializer calls it in from_members, which visit_map and from_nested share.
  • The PartiQL parameter checks (check_value in crates/core/src/partiql/params.rs) call it in place of their own copy of the rule. parse_parameters no longer strips the ignored members first, because the deserializer ignores them itself.
  • The dynamodb:LeadingKeys reader (extract_typed_value in crates/server/src/leading_keys.rs) and the per partition throttling key (extract_partition_value in crates/server/src/throttle_helpers.rs) took the first member of a value object. They now call type_descriptor, so they read the member the engine reads. A key with no descriptor left or with two binds no dynamodb:LeadingKeys, and the engine refuses that request before it reads or writes an item.
  • The ExpressionAttributeValues check wraps every value with no descriptor left, as it wrapped {}.
  • REQ-TYPE-001 in docs/design/01-requirements.md and the reader contract in crates/core/src/backup_format/data_file.rs state the rule.

Two readers of stored and imported lines use the same deserializer:

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 attribute a. G is a GetItem with the shape as the key. In Q and F the empty and the more than one datatypes texts come as ExpressionAttributeValues contains invalid value: <text> for key :z. In P and G they are bare. A shape that passes gets ResourceNotFoundException in F, P and G, and the unused value text in Q.

Shape DynamoDB ExtendDB before
{"S": "a", "X": "1"}, {"X": "1", "S": "a"} passes more than one datatypes
{"S": null, "N": "1"}, {"N": "1", "S": null}, {"S": "a", "N": null, "X": "1"} passes more than one datatypes
{"NULL": true, "S": null}, {"BOOL": false, "S": null} passes more than one datatypes
{"S": "a", "N": "1"} more than one datatypes more than one datatypes
{"X": "1"} empty SerializationException, unknown AttributeValue type descriptor: X
{"S": null} empty serde's text for the S payload
{"S": null, "X": "1"}, {"S": null, "N": null} empty more than one datatypes
{} empty empty
{"N": "bob", "X": "1"} The parameter cannot be converted to a numeric value: bob more than one datatypes

In a PutItem item, an L element and an M value 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, which main ignores 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 are backup_store spool privacy tests. On this host every parent directory of the spool belongs to another user, and the same 5 fail on main.
  • cargo +1.97.0 clippy -p extenddb-core -p extenddb-server -p extenddb-engine --all-targets -- -D warnings and cargo +1.97.0 fmt --all -- --check are clean.
  • A control put back the reading of main and kept the tests. Then 6 core tests and 1 engine test failed.
  • Against a release build on SQLite, 53 of the 64 measured requests got the answer of DynamoDB, and main gets 7 of them. Q6 and F6 ({"S": "a", "N": "1"}) get the bare more than one datatypes text, as on main, 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 an N in the values (fix(query): check Query values against the key schema and the number rules #544 adds that).
  • On a table that exists, PutItem with {"S": "v", "X": "1"} as a stored a as {"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.
  • A principal had a policy that fenced dynamodb:LeadingKeys to 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 with KeyConditionExpression and with KeyConditions. PartiQL SELECT, UPDATE, DELETE, INSERT, BatchExecuteStatement and ExecuteTransaction were among them too. The server refused all 60 requests with AccessDeniedException. The item of the other partition stayed as it was after the 39 write requests.
  • 36 PartiQL parameter shapes went through the parameter checks and the deserializer on main and on this PR, with the same output.
  • The Python tests of item operations, Query and Scan, AttributeValue validation and PartiQL passed against the SQLite build: 814 passed and 1 xfailed.
  • PostgreSQL, MongoDB and Cassandra did not run on this host. A build that keeps the request's member order (with the MongoDB crate) did not run here either. The unit tests give type_descriptor the members in both orders.
  • The last amend changed doc comments, the REQ-TYPE-001 line and the commit message. The runs above used the commit before it.

Production is +101 -95 and the tests are +236 -122.

Conflicts that this PR adds, with their resolutions:

shape_fault_first in crates/engine/src/query_key_values.rs, on the branch of #1260 and the PRs under it, matches the text unknown 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

  • 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.

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

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| {

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 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")),

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.

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"}`

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.

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.

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

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