hasura/graphql-engine · error · AggregateBooleanExpressionError
the order by expression '{order_by_expression}' could not be
Error message
the order by expression '{order_by_expression}' could not be found What it means
When resolving aggregate boolean expressions that involve ordering (e.g. finding min/max by ordering), the referenced order-by expression must exist among those defined on the aggregate expression. This error is thrown when the qualified order-by expression name cannot be found.
Source
Thrown at v3/crates/metadata-resolve/src/stages/aggregate_boolean_expressions/types.rs:228
"type mismatch between the '{count_type}' aggregate (return type: '{count_return_type}') and the specified boolean expression type '{boolean_expression_type}' (operand type: '{boolean_expression_operand_type}')"
)]
CountAggregateTypeMismatch {
count_type: CountAggregateType,
count_return_type: QualifiedTypeName,
boolean_expression_type: BooleanExpressionTypeIdentifier,
boolean_expression_operand_type: QualifiedTypeName,
},
#[error(
"the operand type '{operand_type}' does not match the operand type of the filter boolean expression type '{boolean_expression_type}': '{boolean_expression_operand_type}'"
)]
FilterInputFilterExpressionTypeMismatch {
operand_type: QualifiedTypeName,
boolean_expression_type: Qualified<CustomTypeName>,
boolean_expression_operand_type: QualifiedTypeName,
},
#[error("the order by expression '{order_by_expression}' could not be found")]
OrderByExpressionNotFound {
order_by_expression: Qualified<OrderByExpressionName>,
},
#[error("the field '{field_name}' is defined more than once in the comparable fields")]
DuplicateComparableFieldsFound { field_name: FieldName },
#[error(
"the field '{field_name}' used in comparable fields is not an aggregatable field defined in the aggregate expression '{aggregate_expression}'"
)]
ComparableFieldNotFound {
field_name: FieldName,
aggregate_expression: Qualified<AggregateExpressionName>,
},
#[error(
"the operand object type '{operand_type}' does not contain the field '{field_name}' used in the comparable fields"
)]View on GitHub (pinned to 724551b9ae)
Solutions
- Check the order-by expression name in the failing metadata and confirm it exists on the aggregate expression
- Restore or rename-back the order_by expression, or update references to its new name
- Run metadata validation to surface dangling order-by references
Example fix
// before order_by: MissingOrder // not defined on aggregate expression // after order_by: DefinedOrder // exists in order_by_expressions
Defensive patterns
Strategy: validation
Validate before calling
let names: HashSet<_> = agg_expr.order_by_expressions.iter().map(|o| o.name.clone()).collect(); assert!(names.contains(&referenced_order_by), "order-by expression not defined");
Type guard
fn order_by_exists(agg: &AggregateExpression, name: &str) -> bool {
agg.order_by_expressions.iter().any(|o| o.name.as_str() == name)
} Try / catch
match resolve(expr) {
Err(ResolveError::OrderByExpressionNotFound { order_by_expression }) => {
// list available order-by expressions and surface a helpful message
}
r => r,
} Prevention
- Grep metadata for an order-by name before renaming/deleting it
- Generate order-by references from the aggregate expression definition
When it happens
Trigger: Referencing an order_by expression by name in an aggregate expression where it is not defined; deleting or renaming an order-by expression in metadata while an aggregate comparison still references it.
Common situations: Renaming order_by_expressions entries in metadata without updating aggregate references; environment metadata drift where the order-by expression exists in one env but not another; typos in the order-by expression name.
Related errors
- the field '{field_name}' used in comparable fields is not an
- could not find a scalar-operanded boolean expression type na
- type mismatch between the aggregation function '{aggregation
- the aggregation function '{aggregation_function_name}' retur
- the {count_type} aggregation cannot be compared to because i
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/46ed29b775846b71.
Report an issue: GitHub.