dgraph-io/dgraph · error

Wrong type %v encountered for func since

Error message

Wrong type %v encountered for func since

What it means

The `since` unary function converts a dateTime value into a float representing seconds elapsed since that time (time.Since divided by 1e9). Unlike the other unary math functions it accepts ONLY types.DateTimeID; any other type — including numerics — returns this error with the encountered type ID.

Source

Thrown at query/aggregator.go:573

	case BIGFLOAT:
		value := a.Value.(big.Float)
		f, _ := value.Float64()
		res.Value = *big.NewFloat(math.Ceil(f)).SetPrec(types.BigFloatPrecision)

	case DEFAULT:
		return errors.Errorf("Wrong type %v encountered for fun ceil", a.Tid)
	}
	return nil
}

func applySince(a, res *types.Val) error {
	if a.Tid == types.DateTimeID {
		a.Value = float64(time.Since(a.Value.(time.Time))) / 1000000000.0
		a.Tid = types.FloatID
		*res = *a
		return nil
	}
	return errors.Errorf("Wrong type %v encountered for func since", a.Tid)
}

type unaryFunc func(a, res *types.Val) error
type binaryFunc func(a, b, res *types.Val) error

var unaryFunctions = map[string]unaryFunc{
	"ln":    applyLn,
	"exp":   applyExp,
	"u-":    applyNeg,
	"sqrt":  applySqrt,
	"floor": applyFloor,
	"ceil":  applyCeil,
	"since": applySince,
}

var binaryFunctions = map[string]binaryFunc{
	"+":       applyAdd,
	"-":       applySub,

View on GitHub (pinned to 759e242be6)

Solutions

  1. Pass only a dateTime-typed predicate or variable to since()
  2. Do not nest or reuse since() output (it returns float, which since rejects)
  3. Verify the predicate is declared dateTime in the schema
  4. If the source is a string date, fix the schema/data to dateTime rather than parsing in-query

Example fix

// before: since on a numeric field
"math since(epochField)"
// after: since on a dateTime predicate
"math since(lastSeen)"
Defensive patterns

Strategy: validation

Validate before calling

// only pass dateTime predicates to since
function validateSince(pred, schema) {
  const t = schema.find(p => p.predicate === pred).type;
  if (t !== 'datetime') throw new Error(pred + ' is not dateTime');
}

Type guard

function isDateTime(v) { return v instanceof Date || (typeof v === 'string' && !isNaN(Date.parse(v))); }

Try / catch

try {
  r = await txn.query(q);
} catch (e) {
  if (String(e).includes('func since')) throw new Error('since() requires a dateTime predicate: ' + e);
  throw e;
}

Prevention

When it happens

Trigger: Calling math since(x) where x is not a dateTime predicate: passing a float/int/string/bool value, or a variable that was already converted to float by a previous since() call.

Common situations: Applying since() twice on the same value (second call sees a float); using since() on a numeric timestamp field expecting epoch math; passing a string date that the schema stores as string instead of dateTime.

Related errors


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