{"record":{"id":"9c98e65ce01d0f8b","repo":"dgraph-io/dgraph","slug":"wrong-type-v-encountered-for-func","errorCode":null,"errorMessage":"Wrong type %v encountered for func +","messagePattern":"Wrong type (.+?) encountered for func \\+","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/aggregator.go","lineNumber":145,"sourceCode":"\t\tif !ok {\n\t\t\treturn ErrorArgsDisagree\n\t\t}\n\t\tif len(aVal) != len(bVal) {\n\t\t\treturn ErrorVectorsNotMatch\n\t\t}\n\t\tcVal := make([]float32, len(aVal))\n\t\tfor i := range aVal {\n\t\t\tcVal[i] = aVal[i] + bVal[i]\n\t\t}\n\t\tc.Value = cVal\n\n\tcase BIGFLOAT:\n\t\taVal, bVal := a.Value.(big.Float), b.Value.(big.Float)\n\t\taVal.Add(&aVal, &bVal)\n\t\tc.Value = aVal\n\n\tcase DEFAULT:\n\t\treturn errors.Errorf(\"Wrong type %v encountered for func +\", a.Tid)\n\t}\n\treturn nil\n}\n\nfunc applySub(a, b, c *types.Val) error {\n\tvBase := getValType(a)\n\tswitch vBase {\n\tcase INT:\n\t\taVal, bVal := a.Value.(int64), b.Value.(int64)\n\t\tif (bVal < 0 && aVal > math.MaxInt64+bVal) ||\n\t\t\t(bVal > 0 && aVal < math.MinInt64+bVal) {\n\t\t\treturn ErrorIntOverflow\n\t\t}\n\t\tc.Value = aVal - bVal\n\n\tcase FLOAT:\n\t\tc.Value = a.Value.(float64) - b.Value.(float64)\n\tcase VFLOAT:","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/aggregator.go#L127-L163","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nmath(a + b) // a untyped/DEFAULT\n// after: ensure schema: a: int .\n// or coerce: math(int(a) + b) only after validating a is numeric","handlingStrategy":"validation","validationCode":"func isNumericVal(v types.Val) bool {\n    t := getValType(&v)\n    return t == INT || t == FLOAT || t == BIGFLOAT\n}","typeGuard":"func isAddable(a, b types.Val) bool {\n    return isNumericVal(a) && isNumericVal(b)\n}","tryCatchPattern":"if err := applyAdd(a, b, c); err != nil {\n    if strings.Contains(err.Error(), \"func +\") {\n        return fmt.Errorf(\"operand type %v not supported for +; declare predicate as int/float\", a.Tid)\n    }\n    return err\n}","preventionTips":["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"],"tags":["query","math","type-conversion"],"backgroundTag":"wrong-operand-type","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}