dgraph-io/dgraph · error
Value of type: %s isn't sortable
Error message
Value of type: %s isn't sortable
What it means
SortWithFacet sorts a slice of Val values that carry facets, and before sorting it validates that every facet value's type is one Dgraph can order. If any value has a TypeID whose Name() is not sortable (e.g. bool, uid-with-facet combos, binary types), the sort is aborted with this error rather than producing a meaningless ordering.
Source
Thrown at types/sort.go:149
toBeSorted1 := byValue{b1}
quickSelect(toBeSorted1, 0, nul-1, n)
}
toBeSorted.values = toBeSorted.values[:n]
sort.Sort(toBeSorted)
return nil
}
// SortWithFacet sorts the given array in-place and considers the given facets to calculate
// the proper ordering.
func SortWithFacet(v [][]Val, ul *[]uint64, l []*pb.Facets, desc []bool, lang string) error {
if len(v) == 0 || len(v[0]) == 0 {
return nil
}
for _, val := range v[0] {
if !IsSortable(val.Tid) {
return errors.Errorf("Value of type: %s isn't sortable", val.Tid.Name())
}
}
var cl *collate.Collator
if lang != "" {
// Collator is nil if we are unable to parse the language.
// We default to bytewise comparison in that case.
if langTag, err := language.Parse(lang); err == nil {
cl = collate.New(langTag)
}
}
b := sortBase{v, desc, ul, l, cl}
toBeSorted := byValue{b}
sort.Sort(toBeSorted)
return nil
}
View on GitHub (pinned to 759e242be6)
Solutions
- Check the predicate's facet value types in the schema and ensure only sortable types (int, float, string, datetime, uid, default) are stored as facets
- Cast or re-map facet values to a sortable type before calling SortWithFacet
- Remove or ignore the offending facet values and sort on the base values with types.Sort instead
- Verify no data corruption: re-query the values and inspect val.Tid before sorting
Example fix
// before
if err := types.SortWithFacet(vals, ul, facets, false, "en"); err != nil { // 'bool' facet -> isn't sortable
return err
}
// after
for _, row := range vals {
for _, fv := range row {
if !types.IsSortable(fv.Tid) {
fv.Tid = types.StringID // coerce/normalize to a sortable type first
}
}
}
if err := types.SortWithFacet(vals, ul, facets, false, "en"); err != nil {
return err
} Defensive patterns
Strategy: validation
Validate before calling
for _, row := range vals {
for _, val := range row {
if !types.IsSortable(val.Tid) {
return fmt.Errorf("skip sort: facet type %s not sortable", val.Tid.Name())
}
}
}
types.SortWithFacet(vals, ul, facets, desc, lang) Type guard
func sortableVal(v types.Val) bool { return types.IsSortable(v.Tid) } Prevention
- Only attach facets of sortable scalar types in your schema/data model
- Check types.IsSortable before sorting any facet-carrying value list
- Keep Val.Tid assignments derived from the schema, not hardcoded
When it happens
Trigger: Calling types.SortWithFacet (directly or via Sort/sortAndPaginateUsingFacet) on a value list where the first row's facet values include a type not in Dgraph's sortable set (Sortable type IDs); typically sorting on a predicate with facets whose value type is bool, datetime with facets unsupported, or a corrupt/mismatched Tid.
Common situations: Sorting query results on an edge that has facets of an unsortable type; sorting mixed-type facet data after a schema change; programmatic pagination via sortAndPaginateUsingFacet on facets attached to non-numeric/string predicates.
Related errors
- Compare not supported for type: %v
- unexpected end of facets
- expected '(' but found %v at facet
- expected key but found %v
- empty facetKeys not allowed
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/373c5c01390173a0.
Report an issue: GitHub.