{"record":{"id":"90266d58c6bd22bf","repo":"apache/beam","slug":"mergeaccumulators-must-be-defined-on-accumulator-v","errorCode":null,"errorMessage":"MergeAccumulators must be defined on accumulator %v","messagePattern":"MergeAccumulators must be defined on accumulator (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/state/state.go","lineNumber":322,"sourceCode":"\t\t})\n\t}\n\t// If AddInput isn't defined, that means we must just have one accumulator type identical to the input type.\n\tif ma := p.MergeAccumulatorsFn(s.Key); ma != nil {\n\t\tvar newVal any\n\t\tif f, ok := ma.(reflectx.Func2x1); ok {\n\t\t\tnewVal = f.Call2x1(acc, val)\n\t\t} else {\n\t\t\tnewVal = f.Call([]any{acc, val})[0]\n\t\t}\n\t\treturn p.WriteValueState(Transaction{\n\t\t\tKey:  s.Key,\n\t\t\tType: TransactionTypeSet,\n\t\t\tVal:  newVal,\n\t\t})\n\t}\n\n\t// Should be taken care of by previous validation\n\tpanic(fmt.Sprintf(\"MergeAccumulators must be defined on accumulator %v\", s))\n}\n\n// Read is used to read this instance of global pipeline state representing a combiner.\n// When a value is not found, returns an empty list and false.\nfunc (s *Combining[T1, T2, T3]) Read(p Provider) (T3, bool, error) {\n\tacc, ok, err := s.readAccumulator(p)\n\tif !ok || err != nil {\n\t\tvar val T3\n\t\treturn val, ok, err\n\t}\n\n\tif eo := p.ExtractOutputFn(s.Key); eo != nil {\n\t\tf, ok := eo.(reflectx.Func1x1)\n\t\tif ok {\n\t\t\treturn f.Call1x1(acc).(T3), true, nil\n\t\t}\n\t\treturn f.Call([]any{acc})[0].(T3), true, nil\n\t}","sourceCodeStart":304,"sourceCodeEnd":340,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/state/state.go#L304-L340","documentation":"This panic in Combining.Add is a last-resort invariant check: a combiner accumulator was asked to merge, but no MergeAccumulators function is defined for the accumulator type. Earlier validation should have rejected such a Combining definition, so reaching this line means an invalid combine specification slipped through. The SDK panics because continuing would silently produce wrong aggregation results.","triggerScenarios":"Constructing beam.Combining / state.Combining with a type that lacks a MergeAccumulators method in its DoFn signature, then calling Add on the combiner state; typically from a malformed combine transformation spec.","commonSituations":"Hand-writing combine function signatures instead of using combine.PerKey/CombinePerKey helpers; refactoring a DoFn and removing MergeAccumulators while the combiner setup still references it; using a custom accumulator type without the required merge method.","solutions":["Define a MergeAccumulators method on the accumulator/DoFn type used in the Combining spec.","Prefer combine.CombinePerKey / combine.CombineGlobally helpers, which validate the signature at graph construction time.","Re-run signature validation on the DoFn (beam.Validate) before building the pipeline so the problem is caught as an error instead of a panic."],"exampleFix":"// before\ntype sumFn struct{}\nfunc (fn *sumFn) CreateAccumulator() int { return 0 }\nfunc (fn *sumFn) AddInput(a, v int) int { return a + v }\n// after\ntype sumFn struct{}\nfunc (fn *sumFn) CreateAccumulator() int { return 0 }\nfunc (fn *sumFn) AddInput(a, v int) int { return a + v }\nfunc (fn *sumFn) MergeAccumulators(a, b int) int { return a + b }","handlingStrategy":"validation","validationCode":"var fn interface{} = myCombinerFn{}\nif _, ok := fn.(interface{ MergeAccumulators(int, int) int }); !ok { return errors.New(\"combiner missing MergeAccumulators\") }","typeGuard":"func hasMergeAccumulators(fn interface{}) bool {\n\t_, ok := fn.(interface{ MergeAccumulators(interface{}, interface{}) interface{} })\n\treturn ok\n}","tryCatchPattern":null,"preventionTips":["Always define CreateAccumulator, AddInput, and MergeAccumulators together on combine DoFns.","Run beam.Validate on DoFns before pipeline construction.","Use combine.CombineGlobally / CombinePerKey helpers that validate signatures up front."],"tags":["go","beam","combiner","missing-method","panic"],"backgroundTag":"method-not-implemented","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}