{"id":"f6c29d502bb71c14","repo":"go-redis/redis","slug":"ft-aggregate-loadall-and-load-are-mutually-exclus","errorCode":null,"errorMessage":"FT.AGGREGATE: LOADALL and LOAD are mutually exclusive","messagePattern":"FT\\.AGGREGATE: LOADALL and LOAD are mutually exclusive","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"search_commands.go","lineNumber":696,"sourceCode":"func (c cmdable) FTAggregate(ctx context.Context, index string, query string) *MapStringInterfaceCmd {\n\targs := []interface{}{\"FT.AGGREGATE\", index, query}\n\tcmd := NewMapStringInterfaceCmd(ctx, args...)\n\t_ = c(ctx, cmd)\n\treturn cmd\n}\n\n// validateFTAggregateOptions validates mutually exclusive combinations of\n// FTAggregateOptions fields before any command arguments are constructed.\nfunc validateFTAggregateOptions(options *FTAggregateOptions) error {\n\tif len(options.Steps) > 0 {\n\t\tif options.Load != nil || options.Apply != nil || options.GroupBy != nil ||\n\t\t\toptions.SortBy != nil || options.SortByMax != 0 {\n\t\t\treturn fmt.Errorf(\"FT.AGGREGATE: Steps cannot be combined with the deprecated Load, Apply, GroupBy, SortBy and SortByMax fields\")\n\t\t}\n\t\tif options.LoadAll {\n\t\t\tfor _, step := range options.Steps {\n\t\t\t\tif step.Load != nil {\n\t\t\t\t\treturn fmt.Errorf(\"FT.AGGREGATE: LOADALL and LOAD are mutually exclusive\")\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\tif options.LoadAll && options.Load != nil {\n\t\treturn fmt.Errorf(\"FT.AGGREGATE: LOADALL and LOAD are mutually exclusive\")\n\t}\n\treturn nil\n}\n\n// appendFTAggregateStep appends the Redis command arguments for a single\n// aggregation pipeline step. Each step must set exactly one of Load, Apply,\n// GroupBy or SortBy.\nfunc appendFTAggregateStep(args []interface{}, step FTAggregateStep) ([]interface{}, error) {\n\tset := 0\n\tif step.Load != nil {\n\t\tset++\n\t}","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/go-redis/redis/blob/36d97525cd8076aed67cddf54778e9ea84550929/search_commands.go#L678-L714","documentation":"Returned by validateFTAggregateOptions when LoadAll is true and any individual step in Steps contains a Load field. LOADALL emits a single LOAD * on the wire, which is semantically incompatible with per-step LOAD clauses; the builder rejects the combination up front.","triggerScenarios":"Setting FTAggregateOptions{LoadAll: true, Steps: []FTAggregateStep{{Load: &FTAggregateLoad{Field: \"price\"}}}}. Triggered during option validation before serialization.","commonSituations":"Enabling LoadAll for convenience while still hand-specifying a step-level LOAD. Migrating LOAD clauses into Steps without clearing the LoadAll flag. Copy-pasting options that already had LoadAll enabled.","solutions":["Drop LoadAll and express all LOADs as step-level Load entries, or keep LoadAll and remove every step-level Load.","Audit the Steps slice to confirm no FTAggregateStep.Load is set when LoadAll is true.","Prefer LoadAll only when you genuinely want every field and have no per-step LOAD requirements."],"exampleFix":"// before\nopts := &FTAggregateOptions{\n    LoadAll: true,\n    Steps:   []FTAggregateStep{{Load: &FTAggregateLoad{Field: \"price\"}}},\n}\n// after (option A: keep LoadAll)\nopts := &FTAggregateOptions{LoadAll: true, Steps: []FTAggregateStep{{Apply: ...}}}\n// after (option B: explicit step LOADs)\nopts := &FTAggregateOptions{Steps: []FTAggregateStep{{Load: &FTAggregateLoad{Field: \"price\"}}}}","handlingStrategy":"validation","validationCode":"func validateLoadAllVsStepLoads(opts *FTAggregateOptions) error {\n\tif !opts.LoadAll { return nil }\n\tfor i, st := range opts.Steps {\n\t\tif st.Load != nil {\n\t\t\treturn fmt.Errorf(\"Steps[%d] has Load while LoadAll is set\", i)\n\t\t}\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat LoadAll as exclusive: never also set a step-level Load.","Prefer LoadAll only when you genuinely want every field; otherwise enumerate step LOADs and leave LoadAll false.","Audit options literals during code review for the LoadAll + step.Load combination."],"tags":["ft-aggregate","validation","load","api-misuse"],"analyzedSha":"36d97525cd8076aed67cddf54778e9ea84550929","analyzedAt":"2026-08-06T01:08:27.376Z","schemaVersion":2}