{"record":{"id":"4db60dafa95237e5","repo":"dgraph-io/dgraph","slug":"unsupported-types-val-tid","errorCode":null,"errorMessage":"Unsupported types.Val.Tid","messagePattern":"Unsupported types\\.Val\\.Tid","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/outputnode.go","lineNumber":694,"sourceCode":"\t\t\treturn boolTrue, nil\n\t\t}\n\t\treturn boolFalse, nil\n\tcase types.DateTimeID:\n\t\tt := v.Value.(time.Time)\n\t\treturn marshalTimeJson(t)\n\tcase types.GeoID:\n\t\treturn geojson.Marshal(v.Value.(geom.T))\n\tcase types.BigFloatID:\n\t\tb := v.Value.(big.Float)\n\t\treturn b.MarshalText()\n\tcase types.UidID:\n\t\treturn []byte(fmt.Sprintf(\"\\\"%#x\\\"\", v.Value)), nil\n\tcase types.PasswordID:\n\t\treturn []byte(fmt.Sprintf(\"%q\", v.Value.(string))), nil\n\tcase types.VFloatID:\n\t\treturn json.Marshal(v.Value.([]float32))\n\tdefault:\n\t\treturn nil, errors.New(\"Unsupported types.Val.Tid\")\n\t}\n}\n\n// marshalTimeJson does what time.MarshalJson does along with supporting RFC3339 non compliant\n// time zones in a timestamp. While go 1.20 changes the behaviour of time.MarshalJSON, we do\n// not want to throw error suddenly because we can't marshal the stored data correctly any more.\nfunc marshalTimeJson(t time.Time) ([]byte, error) {\n\t_, offset := t.Zone()\n\t// normal case\n\tif types.GoodTimeZone(offset) {\n\t\treturn t.MarshalJSON()\n\t}\n\n\t// If zone >23 or <-23, we need to handle this case ourselves.\n\t// This is because, in go1.20, MarshalJSON fails for invalid zones.\n\t// We, for now, call MarshalJSON for timestamp without the zone (or making it UTC zone).\n\tb, err := t.Add(time.Duration(offset) * time.Second).UTC().MarshalJSON()\n\tif err != nil {","sourceCodeStart":676,"sourceCodeEnd":712,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/outputnode.go#L676-L712","documentation":"valToBytes switches on the scalar type ID (types.Val.Tid) of a value when encoding query output. If the type ID is not one of the handled scalar kinds (default branch), Dgraph does not know how to serialize it and returns this error — usually meaning an unhandled or corrupted value type reached the output encoder.","triggerScenarios":"A predicate's stored value type has no JSON encoder case in valToBytes (e.g. a newly added or internal-only types.Val Tid), or schema/type coercion produced a Val with an unexpected Tid passed through getObjectVal or AddListValue.","commonSituations":"Dgraph version upgrades introducing new types not handled by older encoder code paths; schema migrations leaving values with mismatched type IDs; programmatic use of the internal types package constructing a Val with an invalid Tid.","solutions":["Upgrade Dgraph to the latest patch release where more scalar types have encoder cases","Inspect the predicate's schema (schema {}) and re-type or re-write the offending values via mutation","Identify the affected node/predicate by bisecting the query, then delete and re-mutate the value with a supported scalar type","If embedding the query package, add a case for the missing types ID in valToBytes"],"exampleFix":"// before\n// query on predicate with unsupported stored type\n{\n  q(func: has(mypred)) { mypred }\n}\n// after: normalize the stored value first via mutation to a supported type (e.g. string/float), then query","handlingStrategy":"try-catch","validationCode":"const schema = await dgraph.schema('mypred');\nif (!['string','float','int','bool','datetime','default'].includes(schema[0]?.type)) throw new Error('unsupported predicate type for output');","typeGuard":"function isSupportedScalarType(tid: string): boolean {\n  return ['string','int','float','bool','datetime','password','default'].includes(tid);\n}","tryCatchPattern":"try {\n  return await dgraph.query(q);\n} catch (e) {\n  if (String(e).includes('Unsupported types.Val.Tid')) {\n    // fall back to fetching uid only, then re-read values with a supported-typed query\n  }\n  throw e;\n}","preventionTips":["Keep Dgraph upgraded to a release whose encoder covers all schema types in use","Avoid writing exotic/internal types programmatically via the types package","Validate schema types before enabling queries on new predicates","Re-mutate values after schema type migrations"],"tags":["json","serialization","type-error","dgraph"],"backgroundTag":"unhandled-value-type","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}