dgraph-io/dgraph · error
Expected a bool but got %v
Error message
Expected a bool but got %v
What it means
parseValue parses variables of type "bool" with strconv.ParseBool, which accepts only 1, t, T, TRUE, true, True, 0, f, F, FALSE, false, False. Any other string fails and is wrapped with 'Expected a bool but got %v'.
Source
Thrown at dql/parser.go:341
Value: i,
}, nil
}
}
case "float":
{
if i, err := strconv.ParseFloat(v.Value, 64); err != nil {
return types.Val{}, errors.Wrapf(err, "Expected a float but got %v", v.Value)
} else {
return types.Val{
Tid: types.FloatID,
Value: i,
}, nil
}
}
case "bool":
{
if i, err := strconv.ParseBool(v.Value); err != nil {
return types.Val{}, errors.Wrapf(err, "Expected a bool but got %v", v.Value)
} else {
return types.Val{
Tid: types.BoolID,
Value: i,
}, nil
}
}
case "float32vector":
{
if i, err := types.ParseVFloat(v.Value); err != nil {
return types.Val{}, errors.Wrapf(err, "Expected a float32vector but got %v", v.Value)
} else {
return types.Val{
Tid: types.VFloatID,
Value: i,
}, nil
}
}View on GitHub (pinned to 759e242be6)
Solutions
- Normalize the value to "true" or "false" before adding it to the variables map
- Trim whitespace from variable values sourced from user input or env
- Map client booleans (yes/no, on/off) explicitly at the boundary
- Pre-validate with strconv.ParseBool in the caller to catch bad values early
Example fix
// before
vars := map[string]string{"$active": "yes"}
// after
vars := map[string]string{"$active": "true"} Defensive patterns
Strategy: validation
Validate before calling
if _, err := strconv.ParseBool(strings.TrimSpace(vars["$active"])); err != nil {
return fmt.Errorf("$active must be a bool: %w", err)
} Prevention
- Normalize yes/no and on/off inputs to true/false at the boundary
- Trim whitespace from form/env-derived variable values
- Only send strconv.ParseBool-compatible literals (true/false/1/0/t/f)
When it happens
Trigger: Supplying a variable with Type "bool" whose Value is not one of strconv.ParseBool's accepted literals — e.g. "$active": "yes", "on", or "True " with trailing whitespace.
Common situations: Frontends sending "yes"/"no" or "1"/"0" from HTML inputs; language-serialized booleans like "true"/"false" from non-Go clients is fine but "Yes"/"NO" is not; trailing whitespace/newlines from form data.
Related errors
- Expected an int but got %v
- Expected a float but got %v
- Expected a float32vector but got %v
- No value found
- Invalid Math expression
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/58ca261d83560276.
Report an issue: GitHub.