Repository navigation
fix(core): check the payloads of a two descriptor value before the count - #1381
LeeroyHannigan wants to merge 1 commit into
Conversation
ExtendDB refused an AttributeValue with two type descriptors for the
count alone. Three shapes show it: {"S": "x", "N": "bob"},
{"SS": ["a", "a"], "N": "bob"} and {"S": "x", "NS": ["1", "1"]}.
UpdateItem, Query and PutItem answered each with the more than one
datatypes text. UpdateItem and Query answered it bare, without the
ExpressionAttributeValues wrapper.
DynamoDB checks the payloads first and the count last. The order is
fixed and does not follow the request's member order. The measurements
ran on 2026-11-23 in us-east-1 on UpdateItem, Query and PutItem. They
cover 91 request shapes, each sent twice, and each set shape in both
member orders.
1. A string set that holds a member twice gets the text that names the
members.
2. The N is read by the PartiQL parameter number rules, not the classic
ones. bob, an empty text, 1e2147483648 and 1.5e-2147483647 are
unconvertible. 1e2147483647 and 1e-131 are underflows, 1e126 is an
overflow, and 39 digits get the digit count text. -0.0 and 1 pass to
the count.
3. A number set two of whose members have one value gets the short
duplicates text.
4. Only then does the count refuse the value.
In UpdateItem and Query every one of these texts, the count's too, comes
as "ExpressionAttributeValues contains invalid value: <text> for key
:v". In PutItem the texts are bare.
The deserializer now runs the three payload checks, in that order, on a
value that type_descriptor would refuse for two descriptors. It refuses
the value for the first fault before the count. The per payload check
is partiql::params::payload_refusal. check_value also calls it for the N
and the number set of a parameter, so the number rules and the duplicate
texts have one home. The string set duplicate text moves into
string_set_duplicates, which string_set and the payload check share.
The ExpressionAttributeValues deserializer names the key for every value
with no single descriptor. It takes the deserializer's own text, in
place of its copy of the empty text. The engine classifies the number
rule texts as a ValidationException through
partiql::number::is_problem_message. So PutItem and the other operations
answer the bare texts with that type.
Other payloads beside a second descriptor were not measured. They are
B, BS, BOOL, NULL, L, M, and the members of a number set that are not
numbers.
They keep the count's text. A forty digit N with an exponent beside a
second descriptor still gets the digit count text, where the service
reports the magnitude. That follows the number check order of #958.
Fixes #1185.
Fixes #1186.
Fixes #1187.
demohan
left a comment
There was a problem hiding this comment.
The payloads this reads before the count get the service's text at 53ae909: for a bad N, SS and NS duplicates, out-of-range exponents and the plain count, outside PartiQL, this head matches us-east-1 on 524 of 528 requests in both member orders on SQLite and PostgreSQL (the other four are an older ExclusiveStartKey wording). Of 1,680 shapes sent twice, the service answered each the same both times; this head matches 852, its base 192, the merge onto main 888 and current main 280, and the backends never differ. Five controls fail the new tests, fmt, both clippy commands, the 1.91.1 check and the core, engine and server tests are clean, CI is green on 59 of 59, and it merges onto main at 222d80a without conflict and passes the 1.94.0 check and the tests there.
One shape main and the base answer as the service does now differs (below). After the merge, main's Query check from #544 runs first, so Query with {"S":"x","N":"1e9999999999"} still gets the overflow text rather than the service's numeric text and #1187 stays open, while the Query rows of #1185 and #1186 already match on main without this. A nested ExpressionAttributeValues value now gets the payload text but without the ExpressionAttributeValues contains invalid value: ... for key :v wrapper our review of #1377 asks for (0 of 96 rows).
I will approve once a number in Unicode digits beside a second descriptor gets the count text again, PartiQL parameters read these payloads as the other readers do, and a test holds the two classifier lines.
crates/core/src/partiql/params.rs:203
PartiQL parameters still get the count text for every payload fault this fixes elsewhere: ExecuteStatement with {"S":"x","SS":["a","a"]} gets the duplicates text from the service and the count here, and 8 of the 88 claimed rows match. The body says this was not measured.
| /// | ||
| /// Returns the service's message for the fault. | ||
| pub(crate) fn payload_refusal(tag: &str, payload: &Value) -> Result<(), String> { | ||
| match (tag, payload) { |
There was a problem hiding this comment.
check_text does not fold Unicode digits as main's Query check does, so PutItem {"S":"x","N":"١"} now gets The parameter cannot be converted to a numeric value: ١, where the service, the base and main give the count text (the service reads ١ as 1); five shapes answer this way.
| // The service checks a string set, then an `N`, then a number set | ||
| // payload before it counts the descriptors, whatever order the | ||
| // members come in (measured 2026-11-23 on UpdateItem, Query and | ||
| // PutItem; the set shapes in both member orders). The other payloads |
There was a problem hiding this comment.
The service reads every payload before counting, not only SS, N and NS, so "The other payloads are not read" does not hold: NULL false, N as a JSON number, bad base64, a non-numeric NS member, an empty SS, BS duplicates, a null SS member and the contents of an L or M get their own text there and the count here (96 of 616 rows match). {"S":"x","SS":["a","a",1]} now gets the duplicates text where the service gives a SerializationException, and a 40-digit number with E200 gets the digit-count text instead of the overflow text. If #1418 is where the rest lands, the comment could say so. docs/design/01-requirements.md:532 still says two or more descriptors always get the count text.
| if msg.contains("parameter values were invalid") | ||
| || msg.contains("may not be empty") | ||
| || msg.contains("contains duplicates") | ||
| || extenddb_core::partiql::number::is_problem_message(&msg) |
There was a problem hiding this comment.
No test holds this classifier line or the one at lib.rs:219: removing either, or dropping one number problem from the list at number.rs:247-257, passes all core, engine and server tests, while a server built without both answers 216 more rows otherwise (PutItem {"S":"v","N":"bob"} gets SerializationException instead of ValidationException).
What
An AttributeValue with two or more type descriptors is now refused as DynamoDB refuses it. DynamoDB checks the payloads first and the count last, in a fixed order that does not follow the request's member order:
One or more parameter values were invalid: Input collection [a, a] contains duplicates.N, read by the PartiQL parameter number rules:The parameter cannot be converted to a numeric value: <text>, or the overflow, underflow or digit count textInput collection contains duplicatesSupplied AttributeValue has more than one datatypes set, must contain exactly one of the supported datatypesIn UpdateItem and Query each of these texts comes inside a wrapper:
ExpressionAttributeValues contains invalid value: <text> for key :v. In PutItem they are bare. Before, ExtendDB refused every such value for the count alone, and UpdateItem and Query sent that text without the wrapper.The changes:
from_membersincrates/core/src/types/attribute_value.rsruns the three payload checks, in that order, on a value thattype_descriptorwould refuse for two descriptors. Then the count refuses the value.payload_refusalincrates/core/src/partiql/params.rs.check_valuealready applied these rules to a PartiQL parameter, and it now callspayload_refusalfor theNand the number set, so the rules have one copy. The string set duplicate text moves intostring_set_duplicates, whichstring_setand the payload check share.ExpressionAttributeValuesdeserializer incrates/core/src/serde_helpers.rsnames the key for every value with no single descriptor. It takes the deserializer's own text, in place of its copy of the empty text.is_problem_messageincrates/core/src/partiql/number.rslets the engine's two error classifiers answer the number texts as aValidationException.The base of this PR is #1377.
Fixes #1185
Fixes #1186
Fixes #1187
Why
DynamoDB was measured in us-east-1 on 23 November 2026, on a table that does not exist. The requests were UpdateItem (
SET a = :v), Query (:vunused beside the key value) and PutItem (the shape as an attribute). 91 request shapes went out twice each, with the same answer both times. Each shape with a set went out in both member orders.{"S": "x", "N": "1"},{"S": "x", "N": "-0.0"}{"S": "x", "N": "bob"}, and the same with0x10or1The parameter cannot be converted to a numeric value: <text>{"S": "x", "N": ""}The parameter cannot be converted to a numeric value{"S": "x", "N": "1e9999999999"},1e-9999999999,1e2147483648,1.5e-2147483647The parameter cannot be converted to a numeric value: <text>{"S": "x", "N": "1e2147483647"},1e-131{"S": "x", "N": "1e126"}{"S": "x", "N": <39 digits>}{"SS": ["a", "a"], "N": "bob"},{"S": "x", "SS": ["a", "a"]}{"S": "x", "NS": ["1", "1"]}{"NS": ["1", "1"], "N": "bob"}bobThe
Nbeside a second descriptor follows the PartiQL parameter rules. The sameNalone in UpdateItem follows the classic rules:1e9999999999alone is an overflow, and an empty text alone gets... a numeric value:with the colon. That reading does not change.Forty digits with
E200orE-200beside a second descriptor get the overflow and the underflow text from DynamoDB. This PR gives the digit count text for them. The PartiQL check order of #1376 (#958) gives DynamoDB's texts, with no change here.Testing done
cargo test -p extenddb-core --lib --no-fail-fast: 1148 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, which fail on this host on every revision.cargo +1.97.0 clippy -p extenddb-core -p extenddb-engine -p extenddb-server --all-targets -- -D warningsandcargo +1.97.0 fmt --all -- --checkare clean.Non a table that does not exist. UpdateItem looks the table up before it checks those numbers, and UpdateItem looks the table up before it checks the numbers in ExpressionAttributeValues #1380 tracks that. On a table that exists, all 58 UpdateItem and PutItem requests get the answer of DynamoDB.{"S": "a", "N": "1"}in Query, now get the wrapper and match. No request that matched on the base changes.dynamodb:LeadingKeysto one partition sent keys with two descriptors and a payload fault, through PutItem, GetItem and Query. ExtendDB refused all 6 requests with the payload texts, and the item of the other partition stayed as it was.Production is +93 -26 and the tests are +109 -14.
These payloads beside a second descriptor were not measured, and they keep the count's text:
BandBSbase64 faultsBOOLandNULLpayloadsLorMA PartiQL parameter with two descriptors and a payload fault still gets the count's text. DynamoDB's answer for it was not measured.
Conflicts that this PR adds, with their resolutions:
crate::deserialize_error. This PR adds a line to that classifier. On top of theirs, drop that line, sincedeserialize_errorcallsis_problem_message.check_valuewithduplicates_as_sent. On top of fix(core): give a set with duplicate members DynamoDB's text #1368, drop theNScall ofpayload_refusalincheck_value.payload_refusalthen usesduplicates_as_sentfor its set arms, andstring_set_duplicatesgoes, so the duplicate texts keep one copy.#544 reads Query values on the raw body before the deserializer, and its
first_faultincrates/engine/src/query_key_values.rshas its own rule for two descriptors. That rule reads theNby the classic check, so it gives the overflow and underflow texts for1e9999999999and1e-9999999999where DynamoDB answers the unconvertible text. On its rebase, a value thattype_descriptorrefuses can take the deserializer's text, and the copy of the rule infirst_faultcan go.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.