{"record":{"id":"45da99f98711e6a5","repo":"apache/beam","slug":"passert-sum-v-v-size-v-want-v-size-v","errorCode":null,"errorMessage":"passert.Sum(%v) = {%v, size: %v}, want {%v, size:%v}","messagePattern":"passert\\.Sum\\((.+?)\\) = (.+?), want (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/testing/passert/sum.go","lineNumber":52,"sourceCode":"\tgrouped := beam.GroupByKey(s, keyed)\n\tbeam.ParDo0(s, &sumFn{Name: name, Size: size, Sum: value}, grouped)\n}\n\ntype sumFn struct {\n\tName string `json:\"name,omitempty\"`\n\tSize int    `json:\"size,omitempty\"`\n\tSum  int    `json:\"sum,omitempty\"`\n}\n\nfunc (f *sumFn) ProcessElement(_ int, values func(*int) bool) error {\n\tvar sum, count, i int\n\tfor values(&i) {\n\t\tcount++\n\t\tsum += i\n\t}\n\n\tif f.Sum != sum || f.Size != count {\n\t\treturn errors.Errorf(\"passert.Sum(%v) = {%v, size: %v}, want {%v, size:%v}\", f.Name, sum, count, f.Sum, f.Size)\n\t}\n\treturn nil\n}\n","sourceCodeStart":34,"sourceCodeEnd":56,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/testing/passert/sum.go#L34-L56","documentation":"passert.Sum's verification DoFn iterates all values for the named sum, computes the actual sum and count, and errors when they differ from the expected Sum and Size recorded at passert.Sum(...) time. The message includes name, actual {sum, size}, and expected {sum, size} so the mismatch is immediately diagnosable.","triggerScenarios":"Calling passert.Sum(p, \"name\", col, sum) where the number of elements or their accumulated total differs from the expected pair — checked inside ProcessElement after iterating values(&i).","commonSituations":"Beam pipeline tests: a transform emits more/fewer elements than intended, element values changed, or the expected sum passed to passert.Sum is stale.","solutions":["Read actual vs expected {sum, size} from the message","If size differs, find why element count changed (extra/dropped records)","If only sum differs, find why values changed","Update the expected sum/size in the test if the new output is correct"],"exampleFix":"// before\npassert.Sum(p, \"sums\", col, 10) // actual 12\n// after\npassert.Sum(p, \"sums\", col, 12)","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := pr.Wait(); err != nil {\n\tvar want, got int\n\tif _, scanErr := fmt.Sscanf(err.Error(), \"passert.Sum(%s\", new(string)); scanErr == nil {\n\t\tt.Fatalf(\"sum mismatch: %v\", err)\n\t}\n\treturn err\n}","preventionTips":["Compute expected sums from the input dataset programmatically","Check element counts before sums to catch missing records","Recompute expected values when input data changes"],"tags":["testing","assertion","sum","apache-beam"],"backgroundTag":"schema-validation-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}