{"record":{"id":"4999085a24efe031","repo":"dgraph-io/dgraph","slug":"wrong-type-v-encountered-for-func-499908","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":352,"sourceCode":"}\n\nfunc applyPow(a, b, c *types.Val) error {\n\tvBase := getValType(a)\n\tswitch vBase {\n\tcase INT:\n\t\tc.Value = math.Pow(float64(a.Value.(int64)), float64(b.Value.(int64)))\n\t\tc.Tid = types.FloatID\n\n\tcase FLOAT:\n\t\t// Fractional power of -ve numbers should not be returned.\n\t\tif a.Value.(float64) < 0 &&\n\t\t\tmath.Abs(math.Ceil(b.Value.(float64))-b.Value.(float64)) > 0 {\n\t\t\treturn ErrorFractionalPower\n\t\t}\n\t\tc.Value = math.Pow(a.Value.(float64), b.Value.(float64))\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 applyLog(a, b, c *types.Val) error {\n\tvBase := getValType(a)\n\tswitch vBase {\n\tcase INT:\n\t\tif a.Value.(int64) < 0 || b.Value.(int64) < 0 {\n\t\t\treturn ErrorNegativeLog\n\t\t} else if b.Value.(int64) == 1 {\n\t\t\treturn ErrorDivisionByZero\n\t\t}\n\t\tc.Value = math.Log(float64(a.Value.(int64))) / math.Log(float64(b.Value.(int64)))\n\t\tc.Tid = types.FloatID\n\n\tcase FLOAT:\n\t\tif a.Value.(float64) < 0 || b.Value.(float64) < 0 {","sourceCodeStart":334,"sourceCodeEnd":370,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/aggregator.go#L334-L370","documentation":"applyPow returns this error when an exponentiation (^) operand has DEFAULT type. Power operations require numeric (int/float) typed values; DEFAULT indicates the operand is untyped or its payload is not numeric. Fractional powers of negative bases raise a separate ErrorFractionalPower.","triggerScenarios":"math(\"^\", a, b) evaluates where an operand's Tid is DEFAULT — e.g. squaring values of an untyped predicate or an empty/unconverted value reaching the math evaluator.","commonSituations":"Score computations (e.g. x^2) over predicates missing schema types; exponent variables bound to uid or empty values; data loaded without type conversion.","solutions":["Give the predicate a numeric schema type (int/float)","Validate both operands are numeric before the ^ expression","Re-set or migrate values stored as the wrong type, then rebuild affected indexes"],"exampleFix":"// before\nmath(score ^ 2) // score: DEFAULT\n// after\n// schema: score: float .\nmath(score ^ 2)","handlingStrategy":"validation","validationCode":"func isPowOperand(v types.Val) bool {\n    t := getValType(&v)\n    return t == INT || t == FLOAT\n}","typeGuard":"func canPow(a, b types.Val) bool {\n    return isPowOperand(a) && isPowOperand(b)\n}","tryCatchPattern":"if err := applyPow(a, b, c); err != nil {\n    switch {\n    case strings.Contains(err.Error(), \"func ^\"):\n        return fmt.Errorf(\"operand type %v not supported for ^; declare numeric schema type\", a.Tid)\n    case errors.Is(err, ErrorFractionalPower):\n        return fmt.Errorf(\"negative base with fractional exponent\")\n    }\n    return err\n}","preventionTips":["Ensure exponentiated predicates are int/float typed","Avoid ^ on uid or empty values","Check sign/exponent combinations for fractional powers","Validate computed score fields carry a schema type"],"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"}