dgraph-io/dgraph · error

Expected a float but got %v

Error message

Expected a float but got %v

What it means

parseValue parses variables of type "float" with strconv.ParseFloat(v.Value, 64). A non-numeric string fails the parse and is wrapped with 'Expected a float but got %v', including the raw value for debugging.

Source

Thrown at dql/parser.go:330

		return types.Val{}, errors.Errorf("No value found")
	}

	switch typ {
	case "int":
		{
			if i, err := strconv.ParseInt(v.Value, 0, 64); err != nil {
				return types.Val{}, errors.Wrapf(err, "Expected an int but got %v", v.Value)
			} else {
				return types.Val{
					Tid:   types.IntID,
					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
			}
		}

View on GitHub (pinned to 759e242be6)

Solutions

  1. Ensure the value is a valid float literal (digits, optional sign, optional exponent, '.' decimal point)
  2. Replace locale decimal commas with dots before submitting the variables map
  3. Verify the variable's declared type matches the data; change to "int" if values are whole numbers
  4. Pre-validate with strconv.ParseFloat on the caller side to fail before the query is parsed

Example fix

// before
vars := map[string]string{"$price": "19,99"}
// after
vars := map[string]string{"$price": "19.99"}
Defensive patterns

Strategy: validation

Validate before calling

if _, err := strconv.ParseFloat(vars["$price"], 64); err != nil {
  return fmt.Errorf("$price must be a float: %w", err)
}

Prevention

When it happens

Trigger: Supplying a variable with Type "float" whose Value cannot be parsed as a float64 — e.g. "$score": "high", "3,14" (comma decimal), or an empty-ish non-numeric string.

Common situations: Locale-formatted numbers with comma decimal separators coming from clients; passing integer-typed units or booleans into float variables; JSON unmarshalling into string variables that lose numeric formatting.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/a21ef691da42bd12. Report an issue: GitHub.