{"record":{"id":"46ed29b775846b71","repo":"hasura/graphql-engine","slug":"the-order-by-expression-order-by-expression-co","errorCode":null,"errorMessage":"the order by expression '{order_by_expression}' could not be found","messagePattern":"the order by expression '(.+?)' could not be found","errorType":"validation","errorClass":"AggregateBooleanExpressionError","httpStatus":null,"severity":"error","filePath":"v3/crates/metadata-resolve/src/stages/aggregate_boolean_expressions/types.rs","lineNumber":228,"sourceCode":"        \"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}')\"\n    )]\n    CountAggregateTypeMismatch {\n        count_type: CountAggregateType,\n        count_return_type: QualifiedTypeName,\n        boolean_expression_type: BooleanExpressionTypeIdentifier,\n        boolean_expression_operand_type: QualifiedTypeName,\n    },\n\n    #[error(\n        \"the operand type '{operand_type}' does not match the operand type of the filter boolean expression type '{boolean_expression_type}': '{boolean_expression_operand_type}'\"\n    )]\n    FilterInputFilterExpressionTypeMismatch {\n        operand_type: QualifiedTypeName,\n        boolean_expression_type: Qualified<CustomTypeName>,\n        boolean_expression_operand_type: QualifiedTypeName,\n    },\n\n    #[error(\"the order by expression '{order_by_expression}' could not be found\")]\n    OrderByExpressionNotFound {\n        order_by_expression: Qualified<OrderByExpressionName>,\n    },\n\n    #[error(\"the field '{field_name}' is defined more than once in the comparable fields\")]\n    DuplicateComparableFieldsFound { field_name: FieldName },\n\n    #[error(\n        \"the field '{field_name}' used in comparable fields is not an aggregatable field defined in the aggregate expression '{aggregate_expression}'\"\n    )]\n    ComparableFieldNotFound {\n        field_name: FieldName,\n        aggregate_expression: Qualified<AggregateExpressionName>,\n    },\n\n    #[error(\n        \"the operand object type '{operand_type}' does not contain the field '{field_name}' used in the comparable fields\"\n    )]","sourceCodeStart":210,"sourceCodeEnd":246,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/metadata-resolve/src/stages/aggregate_boolean_expressions/types.rs#L210-L246","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\norder_by: MissingOrder  // not defined on aggregate expression\n\n// after\norder_by: DefinedOrder   // exists in order_by_expressions","handlingStrategy":"validation","validationCode":"let names: HashSet<_> = agg_expr.order_by_expressions.iter().map(|o| o.name.clone()).collect();\nassert!(names.contains(&referenced_order_by), \"order-by expression not defined\");","typeGuard":"fn order_by_exists(agg: &AggregateExpression, name: &str) -> bool {\n    agg.order_by_expressions.iter().any(|o| o.name.as_str() == name)\n}","tryCatchPattern":"match resolve(expr) {\n    Err(ResolveError::OrderByExpressionNotFound { order_by_expression }) => {\n        // list available order-by expressions and surface a helpful message\n    }\n    r => r,\n}","preventionTips":["Grep metadata for an order-by name before renaming/deleting it","Generate order-by references from the aggregate expression definition"],"tags":["rust","order-by","aggregate","metadata","not-found"],"backgroundTag":null,"analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}