{"record":{"id":"9347dd8f139126a9","repo":"hasura/graphql-engine","slug":"the-following-aggregate-expression-is-defined-more","errorCode":null,"errorMessage":"the following aggregate expression is defined more than once: {name}","messagePattern":"the following aggregate expression is defined more than once: (.+?)","errorType":"validation","errorClass":"AggregateExpressionError","httpStatus":null,"severity":"error","filePath":"v3/crates/metadata-resolve/src/stages/aggregates/types.rs","lineNumber":101,"sourceCode":"    pub count_distinct_field_name: ast::Name,\n\n    pub select_output_type_name: ast::TypeName,\n}\n\n#[derive(Debug, thiserror::Error, PartialEq, Eq, Clone)]\npub enum AggregateExpressionIssue {\n    #[error(\n        \"the aggregate expression {name} defines a graphql section but it will not appear in the GraphQL API unless {config_name} is also configured in the GraphqlConfig\"\n    )]\n    ConfigMissingFromGraphQlConfig {\n        name: Qualified<AggregateExpressionName>,\n        config_name: String,\n    },\n}\n\n#[derive(Debug, thiserror::Error)]\npub enum AggregateExpressionError {\n    #[error(\"the following aggregate expression is defined more than once: {name}\")]\n    DuplicateAggregateExpressionDefinition {\n        name: Qualified<AggregateExpressionName>,\n    },\n\n    #[error(\n        \"the name used by {config_name} from the GraphqlConfig conflicts with the aggregatable field name {aggregatable_field_name} in the aggregate expression {name}\"\n    )]\n    AggregatableFieldNameConflict {\n        name: Qualified<AggregateExpressionName>,\n        config_name: String,\n        aggregatable_field_name: FieldName,\n    },\n\n    #[error(\n        \"the name used by {config_name} from the GraphqlConfig conflicts with the aggregation function name {function_name} in the aggregate expression {name}\"\n    )]\n    AggregationFunctionNameConflict {\n        name: Qualified<AggregateExpressionName>,","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/v3/crates/metadata-resolve/src/stages/aggregates/types.rs#L83-L119","documentation":"Two aggregate expression definitions in the metadata share the same qualified name, so the resolver cannot unambiguously produce an aggregate expression for that name. Duplicate definitions must be removed or renamed.","triggerScenarios":"Declaring the same Qualified<AggregateExpressionName> (same subgraph + name) in two aggregate expression files, or re-including the same metadata document twice during composition.","commonSituations":"Copy-pasting an aggregate expression YAML and forgetting to rename it; merging metadata crates that both define the expression; accidental double-application of metadata documents in a build pipeline.","solutions":["Search the metadata for the duplicate name shown in the error and delete or rename one definition.","Check for accidental double-inclusion of the same metadata file/document in the build.","Ensure each subgraph defines its expressions with unique names if both must coexist."],"exampleFix":"# before\naggregate_expressions:\n  - name: avg_rating   # file A\n  - name: avg_rating   # file B (duplicate)\n# after\naggregate_expressions:\n  - name: avg_rating   # file A\n  - name: avg_rating_v2 # file B, renamed","handlingStrategy":"try-catch","validationCode":"let mut seen = HashSet::new();\nfor expr in &metadata.aggregate_expressions {\n    assert!(seen.insert(expr.name.clone()),\n        \"duplicate aggregate expression definition: {}\", expr.name);\n}","typeGuard":null,"tryCatchPattern":"match resolve_aggregates(&ctx) {\n    Err(errors) => {\n        for e in &errors {\n            if let AggregateExpressionError::DuplicateAggregateExpressionDefinition { name } = e {\n                eprintln!(\"duplicate aggregate expression: {} — remove or rename one definition\", name);\n            }\n        }\n    }\n    Ok(v) => { /* ... */ }\n}","preventionTips":["Give copy-pasted aggregate expressions a new name immediately.","Check for duplicate document inclusion when composing multiple metadata crates."],"tags":["metadata","duplicate-definition","aggregate-expression"],"backgroundTag":"duplicate-metadata-definition","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}