apache/beam · error
unexpected number of params in method %v. got: %v, want: %v
Error message
unexpected number of params in method %v. got: %v, want: %v or optionally %v if first param is of type context.Context
What it means
validateSdfSigNumbers checks that each required SDF method (e.g. CreateInitialRestriction, SplitRestriction, RestrictionSize, CreateTracker, ProcessElement) has an expected number of parameters; one extra leading context.Context parameter is tolerated. This error is thrown when a method's total parameter count is neither reqParamNum nor reqParamNum+1 with a leading context.Context.
Source
Thrown at sdks/go/pkg/beam/core/graph/fn.go:956
splitRestrictionName: num + 1,
restrictionSizeName: num + 1,
createTrackerName: 1,
truncateRestrictionName: num + 1,
}
optionalSdfs := map[string]bool{
truncateRestrictionName: true,
}
reqReturnNum := 1
for _, name := range sdfNames {
method, ok := fn.methods[name]
if !ok && optionalSdfs[name] {
continue
}
reqParamNum := reqParamNums[name]
if !sdfHasValidParamNum(method.Param, reqParamNum) {
err := errors.Errorf("unexpected number of params in method %v. got: %v, want: %v or optionally %v "+
"if first param is of type context.Context", name, len(method.Param), reqParamNum, reqParamNum+1)
return errors.SetTopLevelMsgf(err, "Unexpected number of parameters in method %v. "+
"Got: %v, Want: %v or optionally %v if first param is of type context.Context. "+
"Check that the signature conforms to the expected signature for %v, and that elements in SDF method "+
"parameters match elements in %v.", name, len(method.Param), reqParamNum, reqParamNum+1,
name, processElementName)
}
if !sdfHasValidReturnNum(method.Ret, reqReturnNum) {
err := errors.Errorf("unexpected number of returns in method %v. got: %v, want: %v or optionally %v "+
"if last value is of type error", name, len(method.Ret), reqReturnNum, reqReturnNum+1)
return errors.SetTopLevelMsgf(err, "Unexpected number of return values in method %v. "+
"Got: %v, Want: %v or optionally %v if last value is of type error. "+
"Check that the signature conforms to the expected signature for %v.",
name, len(method.Ret), reqReturnNum, reqReturnNum+1, name)
}
}
return nil
}View on GitHub (pinned to 12126d8942)
Solutions
- Adjust the method so it has exactly the required number of parameters for that SDF role, optionally preceded by one context.Context parameter.
- If you added context.Context, confirm it is the FIRST parameter of the method.
- For ProcessElement, ensure it takes the RTracker plus the same element (and optional key/value) parameters as CreateInitialRestriction.
- Check the reqParamNums table in fn.go for the exact expected count of the method name reported in the error.
Example fix
// before
func (fn *myFn) CreateTracker(r myRestriction, extra int) *myTracker { ... }
// after
func (fn *myFn) CreateTracker(r myRestriction) *myTracker { ... } Defensive patterns
Strategy: validation
Validate before calling
// Validate param counts (allowing optional leading context.Context) before beam.TrySdf:
func checkParamCount(t reflect.Type, name string, want int) error {
m, ok := t.MethodByName(name)
if !ok { return fmt.Errorf("missing method %s", name) }
n := m.Type.NumIn() - 1
if n == want || (n == want+1 && m.Type.In(1) == reflect.TypeOf((*context.Context)(nil)).Elem()) {
return nil
}
return fmt.Errorf("%s: got %d params, want %d (+optional ctx)", name, n, want)
} Prevention
- Always put context.Context first if used in SDF methods
- Follow the canonical SDF signature table in the Beam Go docs
- Add unit tests that construct the DoFn at pipeline-build time to fail fast
When it happens
Trigger: Declaring an SDF method with too few or too many parameters — e.g. CreateTracker with two params besides context, or ProcessElement missing its restriction-tracker parameter; also passing a non-context type as the extra first parameter.
Common situations: Copying method signatures from Java/Python SDF examples into Go; adding a context.Context not in the leading position; forgetting to add the RTracker param to ProcessElement when adding SDF methods; typos in parameter lists during refactoring.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- invalid number of main input params in method %v. got: %v, w
- unexpected number of returns in method %v. got: %v, want: %v
- not all required SplittableDoFn methods are present. Missing
- Mismatched restriction type in method %v, parameter at index
- Invalid output type in method %v, return value at index %v.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/cce0df53d2a8e97d.
Report an issue: GitHub.