{"record":{"id":"eaeed7233d547d5b","repo":"SigNoz/signoz","slug":"group-by-is-invalid-w","errorCode":null,"errorMessage":"group by is invalid %w","messagePattern":"group by is invalid %w","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/query-service/model/v3/v3.go","lineNumber":1080,"sourceCode":"\tif b.Filters != nil {\n\t\tif err := b.Filters.Validate(); err != nil {\n\t\t\treturn fmt.Errorf(\"filters are invalid: %w\", err)\n\t\t}\n\t}\n\tif b.GroupBy != nil {\n\t\t// if len(b.GroupBy) > 0 && panelType == PanelTypeList {\n\t\t// \treturn fmt.Errorf(\"group by is not supported for list panel type\")\n\t\t// }\n\n\t\tif panelType == PanelTypeValue && len(b.GroupBy) > 0 {\n\t\t\tif err := b.SecondaryAggregation.Validate(); err != nil {\n\t\t\t\treturn fmt.Errorf(\"series aggregation is required for value type panel with group by: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tfor _, groupBy := range b.GroupBy {\n\t\t\tif err := groupBy.Validate(); err != nil {\n\t\t\t\treturn fmt.Errorf(\"group by is invalid %w\", err)\n\t\t\t}\n\t\t}\n\n\t\tif b.DataSource == DataSourceMetrics && len(b.GroupBy) > 0 && b.SpaceAggregation == SpaceAggregationUnspecified {\n\t\t\tif b.AggregateOperator == AggregateOperatorNoOp || b.AggregateOperator == AggregateOperatorRate {\n\t\t\t\treturn fmt.Errorf(\"group by requires aggregate operator other than noop or rate\")\n\t\t\t}\n\t\t}\n\t}\n\n\tif b.Having != nil {\n\t\tfor _, having := range b.Having {\n\t\t\tif err := having.Operator.Validate(); err != nil {\n\t\t\t\treturn fmt.Errorf(\"having operator is invalid: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n","sourceCodeStart":1062,"sourceCodeEnd":1098,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/model/v3/v3.go#L1062-L1098","documentation":"Each group-by entry is validated via AttributeKey.Validate; failure means the key is empty or the entry is otherwise malformed.","triggerScenarios":"A groupBy array containing an element with an empty key or missing required attribute fields.","commonSituations":"Dynamically building groupBy from user selections where an empty selection slips through.","solutions":["Filter out empty selections before adding to groupBy","Ensure each groupBy item has a non-empty key (and type/dataType where applicable)"],"exampleFix":"// before\n\"groupBy\":[{\"key\":\"\"}]\n// after\n\"groupBy\":[{\"key\":\"service.name\"}]","handlingStrategy":"validation","validationCode":"for _, g := range q.GroupBy { if strings.TrimSpace(g.Key) == \"\" { return errors.New(\"groupBy key required\") } }","typeGuard":"func hasValidGroupBy(gb []v3.AttributeKey) bool { for _, g := range gb { if g.Key == \"\" { return false } }; return true }","tryCatchPattern":null,"preventionTips":["Filter empty selections before building groupBy arrays"],"tags":["go","group-by","attribute-key"],"backgroundTag":"query-payload-validation-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}