dgraph-io/dgraph · error
Wrong type %v encountered for func +
Error message
Wrong type %v encountered for func +
What it means
applyAdd returns this error when an addition (+) operand has DEFAULT type, i.e. the value's type id is unset or unsupported for arithmetic. Dgraph only adds int/float/bigfloat typed values; a DEFAULT-typed operand indicates missing or untyped data reaching the math evaluator.
Source
Thrown at query/aggregator.go:145
if !ok {
return ErrorArgsDisagree
}
if len(aVal) != len(bVal) {
return ErrorVectorsNotMatch
}
cVal := make([]float32, len(aVal))
for i := range aVal {
cVal[i] = aVal[i] + bVal[i]
}
c.Value = cVal
case BIGFLOAT:
aVal, bVal := a.Value.(big.Float), b.Value.(big.Float)
aVal.Add(&aVal, &bVal)
c.Value = aVal
case DEFAULT:
return errors.Errorf("Wrong type %v encountered for func +", a.Tid)
}
return nil
}
func applySub(a, b, c *types.Val) error {
vBase := getValType(a)
switch vBase {
case INT:
aVal, bVal := a.Value.(int64), b.Value.(int64)
if (bVal < 0 && aVal > math.MaxInt64+bVal) ||
(bVal > 0 && aVal < math.MinInt64+bVal) {
return ErrorIntOverflow
}
c.Value = aVal - bVal
case FLOAT:
c.Value = a.Value.(float64) - b.Value.(float64)
case VFLOAT:View on GitHub (pinned to 759e242be6)
Solutions
- Declare a concrete scalar type (int/float) in the schema for predicates used in math
- Coerce operands explicitly with math functions (e.g. math(val) via typed vars) before +
- Filter out nodes where the value is missing before applying arithmetic
Example fix
// before math(a + b) // a untyped/DEFAULT // after: ensure schema: a: int . // or coerce: math(int(a) + b) only after validating a is numeric
Defensive patterns
Strategy: validation
Validate before calling
func isNumericVal(v types.Val) bool {
t := getValType(&v)
return t == INT || t == FLOAT || t == BIGFLOAT
} Type guard
func isAddable(a, b types.Val) bool {
return isNumericVal(a) && isNumericVal(b)
} Try / catch
if err := applyAdd(a, b, c); err != nil {
if strings.Contains(err.Error(), "func +") {
return fmt.Errorf("operand type %v not supported for +; declare predicate as int/float", a.Tid)
}
return err
} Prevention
- Declare scalar schema types for all predicates used in math()
- Coerce with int()/float() math functions when types may vary
- Filter out nodes with missing values before arithmetic
- Check that fetched values are not uid or empty before math
When it happens
Trigger: A math expression like math("+", a, b) evaluates where one operand resolved to DEFAULT type — e.g. the predicate had no schema type, the value was empty/uid, or conversion earlier in the pipeline left the type unset.
Common situations: Math functions applied to predicates without a declared scalar type; operations on empty optional values; summing over values fetched from an untyped or uid predicate.
Related errors
- Wrong type %v encountered for func -
- Wrong type %v encountered for func %%
- Wrong type %v encountered for func ^
- Wrong type %v encountered for func log
- Fail to convert from api.Value to types.Val
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/9c98e65ce01d0f8b.
Report an issue: GitHub.