diff --git a/crates/core/src/validation/mod.rs b/crates/core/src/validation/mod.rs index c186071a..9bf4ea69 100755 --- a/crates/core/src/validation/mod.rs +++ b/crates/core/src/validation/mod.rs @@ -1007,6 +1007,12 @@ fn ordered_indexes<'b, 'a>(indexes: &'b [IndexKeyRef<'a>]) -> Vec<&'b IndexKeyRe ordered } +/// Readable flags for the `is_query` parameter of [`validate_select_projection`]. +/// Real DynamoDB prepends `1 validation error detected: ` to some rejections for +/// Query but not for Scan, so callers pass one of these instead of a bare bool. +pub const IS_QUERY: bool = true; +pub const IS_SCAN: bool = false; + /// Validate the `Select` value against `ProjectionExpression` / `AttributesToGet` /// presence and `IndexName`. Shared by Query and Scan so both reject the same /// invalid combinations with the same messages. @@ -1026,6 +1032,7 @@ pub fn validate_select_projection( has_projection: bool, has_attributes_to_get: bool, has_index_name: bool, + is_query: bool, ) -> Result<(), DynamoDbError> { if has_projection { let incompatible = match select { @@ -1035,9 +1042,16 @@ pub fn validate_select_projection( _ => None, }; if let Some(what) = incompatible { - return Err(DynamoDbError::ValidationException(format!( - "Cannot specify the ProjectionExpression when choosing to get {what}" - ))); + // Real DynamoDB prepends "1 validation error detected: " to this + // rejection for Query, but NOT for Scan. + let body = + format!("Cannot specify the ProjectionExpression when choosing to get {what}"); + let msg = if is_query { + format!("1 validation error detected: {body}") + } else { + body + }; + return Err(DynamoDbError::ValidationException(msg)); } } if matches!(select, Some(Select::SpecificAttributes)) @@ -1119,6 +1133,29 @@ pub fn validate_conditional_operator_usage( } } +/// Reject `Select=ALL_ATTRIBUTES` against a global secondary index whose +/// projection type is not `ALL` (such an index cannot serve every attribute). +/// Shared by Query and Scan so both reject with the identical message; a no-op +/// unless a GSI is targeted with `Select=ALL_ATTRIBUTES`. +/// +/// # Errors +/// +/// Returns `DynamoDbError::ValidationException` when the combination is invalid. +pub fn validate_all_attributes_index_support( + select: Option