{"record":{"id":"8942f19e56d6f8e8","repo":"hasura/graphql-engine","slug":"the-count-type-aggregation-cannot-be-compared-to","errorCode":null,"errorMessage":"the {count_type} aggregation cannot be compared to because it is not enabled on the aggregate expression '{aggregate_expression}'","messagePattern":"the (.+?) aggregation cannot be compared to because it is not enabled on the aggregate expression '(.+?)'","errorType":"validation","errorClass":"AggregateBooleanExpressionError","httpStatus":null,"severity":"error","filePath":"v3/crates/metadata-resolve/src/stages/aggregate_boolean_expressions/types.rs","lineNumber":201,"sourceCode":"    #[error(\n        \"type mismatch between the aggregation function '{aggregation_function_name}' (return type: '{aggregation_function_return_type}') and the specified boolean expression type '{boolean_expression_type}' (operand type: '{boolean_expression_operand_type}')\"\n    )]\n    AggregationFunctionTypeMismatch {\n        aggregation_function_name: AggregationFunctionName,\n        aggregation_function_return_type: QualifiedTypeName,\n        boolean_expression_type: BooleanExpressionTypeIdentifier,\n        boolean_expression_operand_type: QualifiedTypeName,\n    },\n\n    #[error(\n        \"the aggregation function '{aggregation_function_name}' returns an array type ({aggregation_function_return_type}). Array types are not supported in aggregate comparisons\"\n    )]\n    ComparisonAgainstArrayTypesNotSupported {\n        aggregation_function_name: AggregationFunctionName,\n        aggregation_function_return_type: QualifiedTypeReference,\n    },\n\n    #[error(\n        \"the {count_type} aggregation cannot be compared to because it is not enabled on the aggregate expression '{aggregate_expression}'\"\n    )]\n    CountAggregateNotEnabled {\n        count_type: CountAggregateType,\n        aggregate_expression: Qualified<AggregateExpressionName>,\n    },\n\n    #[error(\n        \"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(","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/metadata-resolve/src/stages/aggregate_boolean_expressions/types.rs#L183-L219","documentation":"Count-style aggregations on an aggregate expression can only be compared against when explicitly enabled on that aggregate expression in the metadata. This error occurs when a comparison references a count aggregate (per CountAggregateType) that the aggregate expression does not have enabled.","triggerScenarios":"Filtering/comparing on a count aggregate (e.g. count or distinct_count) on an AggregateExpressionName whose metadata does not enable that count type for comparison; using a comparative aggregate on a count that was never configured.","commonSituations":"Hand-writing aggregate expression metadata and forgetting to enable the count aggregation; disabling a count aggregate in metadata while queries or other metadata still compare against it; version upgrades that changed which counts are enabled by default.","solutions":["Enable the count aggregate (the specific CountAggregateType) on the aggregate expression in metadata","If it was disabled intentionally, update the query/filter to use a different enabled aggregate","Validate metadata after changes to catch disabled-aggregate references early"],"exampleFix":"// before\naggregate_expression: MyAgg  // count not enabled\nfilter: { count: { _gt: 10 } }\n\n// after\naggregate_expression: MyAgg  // enable count aggregate\nfilter: { count: { _gt: 10 } }","handlingStrategy":"validation","validationCode":"let enabled: HashSet<_> = agg_expr.enabled_count_aggregates.iter().collect();\nassert!(enabled.contains(&count_type), \"{count_type} not enabled on {}\", agg_expr.name);","typeGuard":"fn count_enabled(agg: &AggregateExpression, t: CountAggregateType) -> bool {\n    agg.enabled_count_aggregates.contains(&t)\n}","tryCatchPattern":"match resolve(expr) {\n    Err(ResolveError::CountAggregateNotEnabled { count_type, aggregate_expression }) => {\n        // enable the count aggregate in metadata or drop the comparison\n    }\n    r => r,\n}","preventionTips":["Declare all count aggregates you intend to compare against when defining the aggregate expression","Validate metadata enables every aggregate referenced by filters"],"tags":["rust","aggregate","count","metadata","configuration"],"backgroundTag":null,"analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}