{"record":{"id":"d107f01cd48f2caa","repo":"dgraph-io/dgraph","slug":"wrong-type-v-encountered-for-func-since","errorCode":null,"errorMessage":"Wrong type %v encountered for func since","messagePattern":"Wrong type (.+?) encountered for func since","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/aggregator.go","lineNumber":573,"sourceCode":"\tcase BIGFLOAT:\n\t\tvalue := a.Value.(big.Float)\n\t\tf, _ := value.Float64()\n\t\tres.Value = *big.NewFloat(math.Ceil(f)).SetPrec(types.BigFloatPrecision)\n\n\tcase DEFAULT:\n\t\treturn errors.Errorf(\"Wrong type %v encountered for fun ceil\", a.Tid)\n\t}\n\treturn nil\n}\n\nfunc applySince(a, res *types.Val) error {\n\tif a.Tid == types.DateTimeID {\n\t\ta.Value = float64(time.Since(a.Value.(time.Time))) / 1000000000.0\n\t\ta.Tid = types.FloatID\n\t\t*res = *a\n\t\treturn nil\n\t}\n\treturn errors.Errorf(\"Wrong type %v encountered for func since\", a.Tid)\n}\n\ntype unaryFunc func(a, res *types.Val) error\ntype binaryFunc func(a, b, res *types.Val) error\n\nvar unaryFunctions = map[string]unaryFunc{\n\t\"ln\":    applyLn,\n\t\"exp\":   applyExp,\n\t\"u-\":    applyNeg,\n\t\"sqrt\":  applySqrt,\n\t\"floor\": applyFloor,\n\t\"ceil\":  applyCeil,\n\t\"since\": applySince,\n}\n\nvar binaryFunctions = map[string]binaryFunc{\n\t\"+\":       applyAdd,\n\t\"-\":       applySub,","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/aggregator.go#L555-L591","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass only a dateTime-typed predicate or variable to since()","Do not nest or reuse since() output (it returns float, which since rejects)","Verify the predicate is declared dateTime in the schema","If the source is a string date, fix the schema/data to dateTime rather than parsing in-query"],"exampleFix":"// before: since on a numeric field\n\"math since(epochField)\"\n// after: since on a dateTime predicate\n\"math since(lastSeen)\"","handlingStrategy":"validation","validationCode":"// only pass dateTime predicates to since\nfunction validateSince(pred, schema) {\n  const t = schema.find(p => p.predicate === pred).type;\n  if (t !== 'datetime') throw new Error(pred + ' is not dateTime');\n}","typeGuard":"function isDateTime(v) { return v instanceof Date || (typeof v === 'string' && !isNaN(Date.parse(v))); }","tryCatchPattern":"try {\n  r = await txn.query(q);\n} catch (e) {\n  if (String(e).includes('func since')) throw new Error('since() requires a dateTime predicate: ' + e);\n  throw e;\n}","preventionTips":["Only apply since() to dateTime-typed predicates","Never chain since(since(x)) — output is float","Confirm schema declares the predicate as dateTime","Store string dates as dateTime in the schema"],"tags":["dgraph","query","datetime","type-mismatch"],"backgroundTag":"math-function-invalid-type","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}