dgraph-io/dgraph · error
Wrong type %v encountered for func %%
Error message
Wrong type %v encountered for func %%
What it means
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.
Source
Thrown at query/aggregator.go:331
}
func applyMod(a, b, c *types.Val) error {
vBase := getValType(a)
switch vBase {
case INT:
if b.Value.(int64) == 0 {
return ErrorDivisionByZero
}
c.Value = a.Value.(int64) % b.Value.(int64)
case FLOAT:
if b.Value.(float64) == 0 {
return ErrorDivisionByZero
}
c.Value = math.Mod(a.Value.(float64), b.Value.(float64))
case DEFAULT:
return errors.Errorf("Wrong type %v encountered for func %%", a.Tid)
}
return nil
}
func applyPow(a, b, c *types.Val) error {
vBase := getValType(a)
switch vBase {
case INT:
c.Value = math.Pow(float64(a.Value.(int64)), float64(b.Value.(int64)))
c.Tid = types.FloatID
case FLOAT:
// Fractional power of -ve numbers should not be returned.
if a.Value.(float64) < 0 &&
math.Abs(math.Ceil(b.Value.(float64))-b.Value.(float64)) > 0 {
return ErrorFractionalPower
}
c.Value = math.Pow(a.Value.(float64), b.Value.(float64))View on GitHub (pinned to 759e242be6)
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
Example fix
// before math(a % 10) // a untyped // after // schema: a: int . math(a % 10)
Defensive patterns
Strategy: validation
Validate before calling
func isModOperand(v types.Val) bool {
t := getValType(&v)
return t == INT || t == FLOAT
} Type guard
func canMod(a, b types.Val) bool {
return isModOperand(a) && isModOperand(b) && a.Value.(float64) != 0 || getValType(&a) == INT
} Try / catch
if err := applyMod(a, b, c); err != nil {
if strings.Contains(err.Error(), "func %") {
return fmt.Errorf("operand type %v not supported for %%; declare as int", a.Tid)
}
return err // includes ErrorDivisionByZero
} Prevention
- 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
When it happens
Trigger: math("%", a, b) evaluates where an operand's Tid is DEFAULT — untyped predicate values, empty data, or values whose earlier conversion failed silently.
Common situations: Modulo over an untyped or uid predicate; bucketing (e.g. mod 10) on values that failed to load; missing schema declarations on computed fields.
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/a8850ce1514e5eb4.
Report an issue: GitHub.