{"record":{"id":"a8850ce1514e5eb4","repo":"dgraph-io/dgraph","slug":"wrong-type-v-encountered-for-func-a8850c","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":331,"sourceCode":"}\n\nfunc applyMod(a, b, c *types.Val) error {\n\tvBase := getValType(a)\n\tswitch vBase {\n\tcase INT:\n\t\tif b.Value.(int64) == 0 {\n\t\t\treturn ErrorDivisionByZero\n\t\t}\n\t\tc.Value = a.Value.(int64) % b.Value.(int64)\n\n\tcase FLOAT:\n\t\tif b.Value.(float64) == 0 {\n\t\t\treturn ErrorDivisionByZero\n\t\t}\n\t\tc.Value = math.Mod(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 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))","sourceCodeStart":313,"sourceCodeEnd":349,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/aggregator.go#L313-L349","documentation":"applyMod returns this error when a modulo (%%) operand has DEFAULT type. Modulo is only defined for int and float typed values in Dgraph's math engine; a DEFAULT type id means the operand carried no usable type. Division-by-zero is reported separately as ErrorDivisionByZero.","triggerScenarios":"math(\"%\", a, b) evaluates where an operand's Tid is DEFAULT — untyped predicate values, empty data, or values whose earlier conversion failed silently.","commonSituations":"Modulo over an untyped or uid predicate; bucketing (e.g. mod 10) on values that failed to load; missing schema declarations on computed fields.","solutions":["Declare the predicate as int (or float) in the schema","Ensure the stored values are actually numeric; re-set malformed values","Filter out nodes with missing values before the modulo expression"],"exampleFix":"// before\nmath(a % 10) // a untyped\n// after\n// schema: a: int .\nmath(a % 10)","handlingStrategy":"validation","validationCode":"func isModOperand(v types.Val) bool {\n    t := getValType(&v)\n    return t == INT || t == FLOAT\n}","typeGuard":"func canMod(a, b types.Val) bool {\n    return isModOperand(a) && isModOperand(b) && a.Value.(float64) != 0 || getValType(&a) == INT\n}","tryCatchPattern":"if err := applyMod(a, b, c); err != nil {\n    if strings.Contains(err.Error(), \"func %\") {\n        return fmt.Errorf(\"operand type %v not supported for %%; declare as int\", a.Tid)\n    }\n    return err // includes ErrorDivisionByZero\n}","preventionTips":["Declare int/float schema types for predicates used with %","Guard against zero divisors before modulo","Filter out missing values before bucketing expressions","Keep bucketing math on int-typed predicates"],"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"}