dgraph-io/dgraph · error

error interpreting appropriate type for %v

Error message

error interpreting appropriate type for %v

What it means

After confirming the value is scalar, convertWithBestEffort uses types.Convert to turn the binary-stored value into the schema type. If that conversion fails, the error is wrapped with "error interpreting appropriate type for %v" — this indicates data in the database cannot be decoded as the declared schema type (corrupt or mismatched data from a mutation).

Source

Thrown at query/query.go:436

func isEmptyIneqFnWithVar(sg *SubGraph) bool {
	return sg.SrcFunc != nil && isInequalityFn(sg.SrcFunc.Name) && len(sg.SrcFunc.Args) == 0 &&
		len(sg.Params.NeedsVar) > 0
}

// convert from task.Val to types.Value, based on schema appropriate type
// is already set in api.Value
func convertWithBestEffort(tv *pb.TaskValue, attr string) (types.Val, error) {
	// value would be in binary format with appropriate type
	tid := types.TypeID(tv.ValType)
	if !tid.IsScalar() {
		return types.Val{}, errors.Errorf("Leaf predicate:'%v' must be a scalar.", attr)
	}

	// creates appropriate type from binary format
	sv, err := types.Convert(types.Val{Tid: types.BinaryID, Value: tv.Val}, tid)
	if err != nil {
		// This can happen when a mutation ingests corrupt data into the database.
		return types.Val{}, errors.Wrapf(err, "error interpreting appropriate type for %v", attr)
	}
	return sv, nil
}

func mathCopy(dst *mathTree, src *dql.MathTree) error {
	// Either we'll have an operation specified, or the function specified.
	dst.Const = src.Const
	dst.Fn = src.Fn
	dst.Val = src.Val
	dst.Var = src.Var

	for _, mc := range src.Child {
		child := &mathTree{}
		if err := mathCopy(child, mc); err != nil {
			return err
		}
		dst.Child = append(dst.Child, child)
	}

View on GitHub (pinned to 759e242be6)

Solutions

  1. Find and fix the corrupt node value for the predicate (re-mutate with a correct value)
  2. Verify the predicate's schema type matches the data actually written
  3. Re-import/re-ingest the affected data after correcting the writer

Example fix

// before
{"set": [{"uid": "0x1", "age": "not-a-number"}]}
// after
{"set": [{"uid": "0x1", "age": 30}]} // matches age: int schema
Defensive patterns

Strategy: try-catch

Validate before calling

// Go: validate value encodes to schema type before mutation
if _, err := types.Convert(types.Val{Tid: tid, Value: v}, tid); err != nil {
    return fmt.Errorf("value %v not convertible to %v for %s", v, tid, attr)
}

Try / catch

val, err := convertWithBestEffort(tv, attr)
if err != nil && strings.Contains(err.Error(), "error interpreting appropriate type") {
    log.Warnf("corrupt value for %s: %v", attr, err)
    // skip node / re-ingest data
    return skipNode(attr)
}

Prevention

When it happens

Trigger: types.Convert fails decoding tv.Val from BinaryID into the schema type — e.g. a mutation wrote bytes that don't parse as the predicate's declared type (bad datetime, invalid number, malformed geo).

Common situations: Corrupt data ingested via bad mutations, bulk loader edge cases, or schema changed to a type incompatible with existing stored values.

Related errors


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