Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
eb370a3
fix(query): check Query values against the key schema and the number …
LeeroyHannigan Oct 24, 2026
f0017ce
fix(query): run the request-time checks on the raw body, enums in the…
LeeroyHannigan Oct 25, 2026
e4f660d
docs(query): name the request-time function in the comments that poin…
LeeroyHannigan Oct 25, 2026
4a4e92f
fix(cassandra): pass the bare index name in IndexNotFound so the Quer…
LeeroyHannigan Oct 24, 2026
03caeed
fix(query): accept Unicode decimal digits in the number check and rep…
LeeroyHannigan Oct 25, 2026
bde92d3
fix(query): leave an unknown type descriptor to the request-time chec…
LeeroyHannigan Oct 25, 2026
2062187
fix(scan): check the numbers in ExpressionAttributeValues at request …
LeeroyHannigan Oct 25, 2026
6f1e284
test(scan): wire tests for the request-time number check and its posi…
LeeroyHannigan Oct 25, 2026
3a633fd
test(query): say which Limit text the service uses beside an unknown …
LeeroyHannigan Oct 25, 2026
d676c6e
fix(scan): report range faults one at a time, shape faults first, and…
LeeroyHannigan Oct 25, 2026
b2aa733
Merge origin/main into fix/query-key-value-types
LeeroyHannigan Nov 6, 2026
44b7b18
test(query): pass the RANGE attributes to resolve_multipart
LeeroyHannigan Nov 6, 2026
0b8e97d
fix(query): order the key value type check and the begins_with refusa…
LeeroyHannigan Nov 6, 2026
e03ac73
Merge fix/query-key-value-types into fix/scan-number-check
LeeroyHannigan Nov 6, 2026
7b0924f
test(query): pin begins_with on a non-key attribute and correct the o…
LeeroyHannigan Nov 6, 2026
1b45b9b
Merge fix/query-key-value-types into fix/scan-number-check
LeeroyHannigan Nov 6, 2026
3663529
Merge origin/main into fix/query-key-value-types
LeeroyHannigan Nov 7, 2026
56ac562
Merge fix/query-key-value-types into fix/scan-number-check
LeeroyHannigan Nov 7, 2026
ce5c103
Merge origin/main into fix/query-key-value-types
LeeroyHannigan Nov 9, 2026
3adc887
Merge fix/query-key-value-types into fix/scan-number-check
LeeroyHannigan Nov 9, 2026
3d7e15f
Merge origin/main into fix/query-key-value-types
LeeroyHannigan Nov 9, 2026
f98573d
Merge fix/query-key-value-types into fix/scan-number-check
LeeroyHannigan Nov 9, 2026
cb2df0b
fix(query): check each value on its own and answer in the service's o…
LeeroyHannigan Nov 11, 2026
54150fe
fix(query): share the key value type check and update three comments
LeeroyHannigan Nov 12, 2026
ba4af88
fix(query): read each payload of a value with several types first
LeeroyHannigan Nov 19, 2026
9e8c063
Merge origin/main into fix/query-key-value-types
LeeroyHannigan Nov 19, 2026
474b23d
fix(query): check ExpressionAttributeNames ahead of the numbers
LeeroyHannigan Nov 19, 2026
cd7e8e8
fix(query): read a null payload as no payload
LeeroyHannigan Nov 19, 2026
bf3f970
fix(query): report an empty name after a value the service cannot read
LeeroyHannigan Nov 19, 2026
99dc134
docs(query): scope four comments on the names checks
LeeroyHannigan Nov 19, 2026
5cd089d
Merge origin/main into fix/query-key-value-types
LeeroyHannigan Nov 23, 2026
680c83b
refactor(query): take three message texts from core
LeeroyHannigan Nov 23, 2026
f07a565
docs(query): give the M member order of the MongoDB build
LeeroyHannigan Nov 23, 2026
467e287
test(query): give the service's text for each shape fault row
LeeroyHannigan Nov 23, 2026
e2d90f1
docs: list three Query differences from DynamoDB
LeeroyHannigan Nov 23, 2026
d7e6ff3
fix(query): find a shape fault in any member and value
LeeroyHannigan Nov 23, 2026
c0ba76a
Merge fix/query-key-value-types into fix/scan-number-check
LeeroyHannigan Nov 23, 2026
039729c
fix(scan): run the request checks in the service's order
LeeroyHannigan Nov 23, 2026
6f722f7
fix(server): run the Scan request checks before the IAM decision
LeeroyHannigan Nov 23, 2026
0e0f078
fix(query): leave the check's answer beside a null member or name
LeeroyHannigan Nov 24, 2026
35910e9
fix(query): name a set fault beside a second type descriptor
LeeroyHannigan Nov 24, 2026
4b5125a
Merge origin/main into fix/query-key-value-types
LeeroyHannigan Nov 24, 2026
ad5f485
Merge fix/query-key-value-types into fix/scan-number-check
LeeroyHannigan Nov 24, 2026
6d74de7
Merge origin/main into fix/query-key-value-types
LeeroyHannigan Nov 24, 2026
330d685
Merge fix/query-key-value-types into fix/scan-number-check
LeeroyHannigan Nov 24, 2026
31c5f3d
Merge origin/main into fix/query-key-value-types
LeeroyHannigan Nov 24, 2026
b33d458
Merge fix/query-key-value-types into fix/scan-number-check
LeeroyHannigan Nov 24, 2026
81b01cb
Merge origin/main into fix/scan-number-check
LeeroyHannigan Nov 25, 2026
009c4c1
Merge branch 'main' into fix/scan-number-check
LeeroyHannigan Nov 27, 2026
4811268
Merge origin/main into fix/scan-number-check
LeeroyHannigan Dec 3, 2026
4c08c09
docs(upgrade): add the v1.2.0 entry for the Scan value checks
LeeroyHannigan Dec 3, 2026
c06130a
Merge origin/main into fix/scan-number-check
LeeroyHannigan Dec 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions crates/engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub mod query_key_values;
mod read_helpers;
mod request_limits;
mod scan;
pub mod scan_request;
mod search_vectors;
mod search_vectors_extended;
mod search_vectors_params;
Expand Down Expand Up @@ -302,8 +303,10 @@ pub(crate) const RETURN_VALUES_MEMBERS: &[&str] =
/// Pre-validate enum fields in a JSON body and return a combined error if
/// multiple are invalid, in the order listed. Whether an operation aggregates
/// its enum violations or stops at the first is per operation on the service
/// (PutItem/DeleteItem/Scan aggregate; UpdateItem and Query stop at the
/// first), so callers choose by passing one list or several sequential calls.
/// (`PutItem` and `DeleteItem` aggregate; `UpdateItem` stops at the first, and
/// so do `Query` and `Scan` for a body whose `ExpressionAttributeValues` the
/// service can read), so callers choose by passing one list or several
/// sequential calls.
pub(crate) fn validate_enum_fields(
body: &serde_json::Value,
fields: &[EnumField<'_>],
Expand Down
28 changes: 15 additions & 13 deletions crates/engine/src/query_key_values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use serde_json::{Map, Value};

mod unreadable;

use unreadable::{readable_for_shape_check, unreadable, unreadable_value_checks};
pub(crate) use unreadable::{readable_for_shape_check, unreadable, unreadable_value_checks};

/// The service's text for a key condition value of the wrong type.
pub const KEY_CONDITION_TYPE_MISMATCH: &str = "One or more parameter values were invalid: Condition parameter type does not match schema type";
Expand All @@ -61,8 +61,8 @@ const NULL_VALUE: &str = "The supplied Item contains a null AttributeValue";
const TYPE_DESCRIPTORS: [&str; 10] = ["SS", "S", "N", "B", "NS", "BS", "M", "L", "NULL", "BOOL"];

/// The members of the two enums the request-time checks read.
const RETURN_CONSUMED_CAPACITY: &[&str] = &["INDEXES", "TOTAL", "NONE"];
const SELECT: &[&str] = &[
pub(crate) const RETURN_CONSUMED_CAPACITY: &[&str] = &["INDEXES", "TOTAL", "NONE"];
pub(crate) const SELECT: &[&str] = &[
"SPECIFIC_ATTRIBUTES",
"COUNT",
"ALL_ATTRIBUTES",
Expand Down Expand Up @@ -150,10 +150,12 @@ pub fn validate_query_request_body(body: &Value) -> Result<(), DynamoDbError> {
/// `Limit` `ValidationException` (measured 2026-10-25 and 2026-11-23);
/// - a member the service reads from a JSON type that `T` refuses: a string
/// in `ConsistentRead` or `ScanIndexForward` that the service reads as a
/// boolean (see [`BOOLEAN_TEXTS`]), and any number in `Limit`. Measured
/// 2026-11-23: `ConsistentRead: "true"` or `"T"`, `ScanIndexForward:
/// "true"` or `"0"`, and `Limit: 1.5` beside `Select: "NOPE"` answer the
/// `Select` text on `Query`, as `ConsistentRead: "true"` does on `Scan`, and
/// boolean (see [`BOOLEAN_TEXTS`]), and any number in `Limit`, `Segment` or
/// `TotalSegments`. Measured 2026-11-23, beside `Select: "NOPE"`:
/// `ConsistentRead: "true"` or `"T"`, `ScanIndexForward: "true"` or `"0"`,
/// and `Limit: 1.5` answer the `Select` text on `Query`, and
/// `ConsistentRead: "true"`, `Segment: 1.5` with `TotalSegments: 2`, and
/// `TotalSegments: 2.5` with `Segment: 0` answer it on `Scan`.
/// `ConsistentRead: "yes"` with a table that does not exist answers
/// `ResourceNotFoundException`. `ConsistentRead: "on"` answers
/// `SerializationException: Unexpected token received from parser`, and
Expand Down Expand Up @@ -196,7 +198,7 @@ pub(crate) fn shape_fault_first<T: DeserializeOwned>(
{
None
}
("Limit", Value::Number(_)) => None,
("Limit" | "Segment" | "TotalSegments", Value::Number(_)) => None,
("ExpressionAttributeNames", Value::Object(names)) => read(
name,
Value::Object(
Expand Down Expand Up @@ -256,7 +258,7 @@ fn query_request_checks(body: &Value) -> Result<(), DynamoDbError> {
if let Some(values) = values
&& values.values().any(unreadable)
{
return unreadable_value_checks(body, values);
return unreadable_value_checks(body, values, validate_no_parameter_mix);
}

if let Some(limit) = body.get("Limit").and_then(Value::as_i64)
Expand Down Expand Up @@ -365,12 +367,12 @@ fn validate_name_keys(body: &Value) -> Result<(), DynamoDbError> {

/// Whether `field` is in the body with a value other than `null`, as a typed
/// `Option` field would deserialize to `Some`.
fn present(body: &Value, field: &str) -> bool {
pub(crate) fn present(body: &Value, field: &str) -> bool {
body.get(field).is_some_and(|v| !v.is_null())
}

/// Whether `field` is a non-empty JSON object or array in the body.
fn non_empty(body: &Value, field: &str) -> bool {
pub(crate) fn non_empty(body: &Value, field: &str) -> bool {
match body.get(field) {
Some(Value::Object(map)) => !map.is_empty(),
Some(Value::Array(items)) => !items.is_empty(),
Expand All @@ -380,7 +382,7 @@ fn non_empty(body: &Value, field: &str) -> bool {

/// The entries of `values` by placeholder, so the reported value is
/// deterministic when several are invalid.
fn sorted_entries(values: &Map<String, Value>) -> Vec<(&String, &Value)> {
pub(crate) fn sorted_entries(values: &Map<String, Value>) -> Vec<(&String, &Value)> {
let mut entries: Vec<(&String, &Value)> = values.iter().collect();
entries.sort_by_key(|(key, _)| *key);
entries
Expand Down Expand Up @@ -562,7 +564,7 @@ fn number_fault(text: &str) -> Option<Fault<'_>> {
/// # Errors
///
/// Returns `DynamoDbError::ValidationException` with the service's text.
fn validate_expression_attribute_value_numbers(
pub(crate) fn validate_expression_attribute_value_numbers(
values: &Map<String, Value>,
) -> Result<(), DynamoDbError> {
match sorted_entries(values)
Expand Down
21 changes: 15 additions & 6 deletions crates/engine/src/query_key_values/unreadable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use serde_json::{Map, Value};

use super::{
RETURN_CONSUMED_CAPACITY, SELECT, TYPE_DESCRIPTORS, first_fault, sorted_entries,
validate_name_keys, validate_names, validate_no_parameter_mix,
validate_name_keys, validate_names,
};

/// Whether the service cannot read `value` as exactly one AttributeValue type:
Expand All @@ -23,7 +23,7 @@ use super::{
/// value an `L` or `M` holds (measured 2026-11-19: `{"S": null}` beside a
/// `Limit` of 0 answers `Value '0' at 'limit'`, as `{"X": "1"}` does). A value
/// of another JSON type is a shape fault instead.
pub(super) fn unreadable(value: &Value) -> bool {
pub(crate) fn unreadable(value: &Value) -> bool {
match value {
Value::Null => true,
Value::Object(map) => {
Expand Down Expand Up @@ -54,7 +54,7 @@ pub(super) fn unreadable(value: &Value) -> bool {
/// 2026-11-11: `{"L": [null, "x"]}`, `{"L": [{"X": "1"}, {"N": 5}]}` and
/// `{"L": [null, {"B": "!!"}]}`, and `{"S": 5, "X": "1"}` and `{"S": 5, "N":
/// "1"}` beside a `Limit` of 0, all answer `SerializationException`.
pub(super) fn readable_for_shape_check(body: &Value) -> Cow<'_, Value> {
pub(crate) fn readable_for_shape_check(body: &Value) -> Cow<'_, Value> {
match body
.get("ExpressionAttributeValues")
.and_then(Value::as_object)
Expand Down Expand Up @@ -129,7 +129,8 @@ fn null_value() -> Value {
/// 'returnConsumedCapacity' failed to satisfy constraint: ...; Value '0' at
/// 'limit' failed to satisfy constraint: Member must have value greater
/// than or equal to 1`;
/// 2. the expression and non-expression parameter mix;
/// 2. the expression and non-expression parameter mix, which
/// `validate_parameter_mix` checks with the operation's members;
/// 3. the `ExpressionAttributeNames` key checks: an invalid key, a key over
/// 255 bytes and an empty map (measured 2026-11-19: an invalid names key
/// beside `{"X": "1"}`, `{}` or `{"N": "1", "S": "x"}` answers the names
Expand Down Expand Up @@ -164,9 +165,17 @@ fn null_value() -> Value {
/// `:a` with `{"X": "1"}` beside `:b` with a null names `:b`, and `:a` with a
/// null beside `:b` with `{"X": "1"}` names `:b`. This order names `:z`, `:a`
/// and `:a` for them.
pub(super) fn unreadable_value_checks(
///
/// The `Scan` request-time checks call this too, after their range checks.
/// Measured on `Scan` 2026-11-23, each request twice: an invalid `Select` and
/// `ReturnConsumedCapacity` beside `{}` answer both clauses in one message,
/// and a null, `{"L": [null]}` or `{"S": null}` beside an invalid `Select`
/// answers the `Select` text. `:a` with `{}` beside `:n` with `{"N": "bob"}`
/// names `:n` there, where this order names `:a`.
pub(crate) fn unreadable_value_checks(
body: &Value,
values: &Map<String, Value>,
validate_parameter_mix: fn(&Value) -> Result<(), DynamoDbError>,
) -> Result<(), DynamoDbError> {
let mut violations: Vec<String> = [
enum_violation(body, "Select", "select", SELECT),
Expand Down Expand Up @@ -197,7 +206,7 @@ pub(super) fn unreadable_value_checks(
)));
}

validate_no_parameter_mix(body)?;
validate_parameter_mix(body)?;
validate_name_keys(body)?;

// The values the service cannot read first; the sort is stable, so each
Expand Down
90 changes: 14 additions & 76 deletions crates/engine/src/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,58 +41,21 @@ pub async fn handle_scan(
body: Value,
ctx: &OperationContext,
) -> Result<DispatchResult, DynamoDbError> {
// Pre-scanned before typed deserialization. Scan AGGREGATES its invalid
// enums with Select's clause ahead of ReturnConsumedCapacity's, the
// opposite of Query on both counts (Query stops at the first, RCC-first).
// Measured 2026-08-24 (us-east-1): both invalid answers "2 validation
// errors detected: ... 'select' ...; ... 'returnConsumedCapacity' ...".
crate::validate_enum_fields(
&body,
&[
crate::EnumField {
json_name: "Select",
valid: &[
"SPECIFIC_ATTRIBUTES",
"COUNT",
"ALL_ATTRIBUTES",
"ALL_PROJECTED_ATTRIBUTES",
],
clause: crate::EnumClause::Named("select"),
},
crate::EnumField {
json_name: "ReturnConsumedCapacity",
valid: &["INDEXES", "TOTAL", "NONE"],
clause: crate::EnumClause::Named("returnConsumedCapacity"),
},
],
)?;
// Request-time checks on the raw body, in the service's order: the Limit,
// Segment and TotalSegments ranges, the ReturnConsumedCapacity enum, the
// expression and non-expression parameter mix, the
// ExpressionAttributeNames checks, every number in
// ExpressionAttributeValues, the set faults, the Select enum. They run
// before typed deserialization so a field that does not deserialize does
// not stop the ones before it; a field of the wrong JSON type is reported
// ahead of them; see `scan_request`.
crate::scan_request::validate_scan_request_body(&body)?;
let input: ScanInput = serde_json::from_value(body).map_err(crate::deserialize_error)?;

// Validate Filter/Projection expressions before the existence
// check; index resolution, Segment/Limit/Select and key checks stay after.

// --- Legacy vs expression mutual exclusivity checks ---
let has_fe = input.filter_expression.is_some();
let has_sf = input.scan_filter.as_ref().is_some_and(|m| !m.is_empty());
let has_pe = input.projection_expression.is_some();
let has_atg = input
.attributes_to_get
.as_ref()
.is_some_and(|a| !a.is_empty());
// check; index resolution, Segment pairing, Select and key checks stay after.
let has_cond_op = input.conditional_operator.is_some();

extenddb_core::validation::validate_no_expression_param_mixing(
&[
("AttributesToGet", has_atg),
("ScanFilter", has_sf),
("ConditionalOperator", has_cond_op),
],
&[
("ProjectionExpression", has_pe),
("FilterExpression", has_fe),
],
)?;

let maps = build_expression_maps(
input.expression_attribute_names.as_ref(),
input.expression_attribute_values.as_ref(),
Expand Down Expand Up @@ -300,7 +263,9 @@ pub async fn handle_scan(
)?;
}

// Validate Segment/TotalSegments — DynamoDB returns different messages per direction
// Validate Segment/TotalSegments pairing. The range of each field is
// checked at request time in validate_scan_request_body; the service
// reports a missing partner with a message per direction.
match (input.segment, input.total_segments) {
(Some(_), None) => {
return Err(DynamoDbError::ValidationException(
Expand All @@ -315,26 +280,6 @@ pub async fn handle_scan(
));
}
(Some(seg), Some(total)) => {
if total < 1 {
return Err(DynamoDbError::ValidationException(
"The parameter TotalSegments should be greater than or equal to 1".to_owned(),
));
}
if total > 1_000_000 {
return Err(DynamoDbError::ValidationException(format!(
"1 validation error detected: Value '{total}' at 'totalSegments' failed to satisfy constraint: Member must have value less than or equal to 1000000"
)));
}
if seg < 0 {
return Err(DynamoDbError::ValidationException(format!(
"1 validation error detected: Value '{seg}' at 'segment' failed to satisfy constraint: Member must have value greater than or equal to 0"
)));
}
if seg > 999_999 {
return Err(DynamoDbError::ValidationException(format!(
"1 validation error detected: Value '{seg}' at 'segment' failed to satisfy constraint: Member must have value less than or equal to 999999"
)));
}
if seg >= total {

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.

No test fails with this check disabled. TotalSegments: 1 accepted has no row either.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 039729c. TestSegmentPairing sends Segment: 5, TotalSegments: 2 alone. It expects the service's text against DynamoDB and this branch's text against ExtendDB, which adds : Segment: 5 is not less than TotalSegments: 2 (#838). With the check disabled that test fails. A second test sends Segment: 0, TotalSegments: 1, and the Scan returns both items.

return Err(DynamoDbError::ValidationException(format!(
"The Segment parameter is zero-based and must be less than parameter TotalSegments: \
Expand All @@ -345,14 +290,7 @@ pub async fn handle_scan(
(None, None) => {}
}

// Validate Limit >= 1
if let Some(limit) = input.limit
&& limit < 1
{
return Err(DynamoDbError::ValidationException(format!(
"1 validation error detected: Value '{limit}' at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1"
)));
}
// Limit >= 1 is checked at request time in validate_scan_request_body.

// For index scans, build a key_info that reflects the index's key schema.
let scan_key_info = if let Some(ref idx) = index_info {
Expand Down
Loading
Loading