{"record":{"id":"373c5c01390173a0","repo":"dgraph-io/dgraph","slug":"value-of-type-s-isn-t-sortable","errorCode":null,"errorMessage":"Value of type: %s isn't sortable","messagePattern":"Value of type: (.+?) isn't sortable","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"types/sort.go","lineNumber":149,"sourceCode":"\t\ttoBeSorted1 := byValue{b1}\n\t\tquickSelect(toBeSorted1, 0, nul-1, n)\n\t}\n\ttoBeSorted.values = toBeSorted.values[:n]\n\tsort.Sort(toBeSorted)\n\n\treturn nil\n}\n\n// SortWithFacet sorts the given array in-place and considers the given facets to calculate\n// the proper ordering.\nfunc SortWithFacet(v [][]Val, ul *[]uint64, l []*pb.Facets, desc []bool, lang string) error {\n\tif len(v) == 0 || len(v[0]) == 0 {\n\t\treturn nil\n\t}\n\n\tfor _, val := range v[0] {\n\t\tif !IsSortable(val.Tid) {\n\t\t\treturn errors.Errorf(\"Value of type: %s isn't sortable\", val.Tid.Name())\n\t\t}\n\t}\n\n\tvar cl *collate.Collator\n\tif lang != \"\" {\n\t\t// Collator is nil if we are unable to parse the language.\n\t\t// We default to bytewise comparison in that case.\n\t\tif langTag, err := language.Parse(lang); err == nil {\n\t\t\tcl = collate.New(langTag)\n\t\t}\n\t}\n\n\tb := sortBase{v, desc, ul, l, cl}\n\ttoBeSorted := byValue{b}\n\tsort.Sort(toBeSorted)\n\treturn nil\n}\n","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/types/sort.go#L131-L167","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nif err := types.SortWithFacet(vals, ul, facets, false, \"en\"); err != nil { // 'bool' facet -> isn't sortable\n    return err\n}\n// after\nfor _, row := range vals {\n    for _, fv := range row {\n        if !types.IsSortable(fv.Tid) {\n            fv.Tid = types.StringID // coerce/normalize to a sortable type first\n        }\n    }\n}\nif err := types.SortWithFacet(vals, ul, facets, false, \"en\"); err != nil {\n    return err\n}","handlingStrategy":"validation","validationCode":"for _, row := range vals {\n    for _, val := range row {\n        if !types.IsSortable(val.Tid) {\n            return fmt.Errorf(\"skip sort: facet type %s not sortable\", val.Tid.Name())\n        }\n    }\n}\ntypes.SortWithFacet(vals, ul, facets, desc, lang)","typeGuard":"func sortableVal(v types.Val) bool { return types.IsSortable(v.Tid) }","tryCatchPattern":null,"preventionTips":["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"],"tags":["sorting","types","facets","dgraph"],"backgroundTag":"type-not-sortable","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}