{"record":{"id":"e45903765689af05","repo":"dgraph-io/dgraph","slug":"while-ordering-and-paginating","errorCode":null,"errorMessage":"While ordering and paginating","messagePattern":"While ordering and paginating","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/query.go","lineNumber":953,"sourceCode":"\t\tsrcFunc.IsCount = sg.SrcFunc.IsCount\n\t\tfor _, arg := range sg.SrcFunc.Args {\n\t\t\tsrcFunc.Args = append(srcFunc.Args, arg.Value)\n\t\t\tif arg.IsValueVar {\n\t\t\t\treturn nil, errors.Errorf(\"Unsupported use of value var\")\n\t\t\t}\n\t\t}\n\t}\n\n\t// If the lang is set to *, query all the languages.\n\tif len(sg.Params.Langs) == 1 && sg.Params.Langs[0] == \"*\" {\n\t\tsg.Params.ExpandAll = true\n\t}\n\n\t// first is to limit how many results we want.\n\tfirst, offset := calculatePaginationParams(sg)\n\tns, err := x.ExtractNamespace(ctx)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"While ordering and paginating\")\n\t}\n\torderParams := sg.createOrderForTask(ns)\n\tsortMsg := &pb.SortMessage{\n\t\tOrder:     orderParams,\n\t\tUidMatrix: sg.uidMatrix,\n\t\tOffset:    int32(sg.Params.Offset),\n\t\tCount:     int32(sg.Params.Count),\n\t\tReadTs:    sg.ReadTs,\n\t}\n\n\tout := &pb.Query{\n\t\tReadTs:       sg.ReadTs,\n\t\tCache:        int32(sg.Cache),\n\t\tAttr:         x.NamespaceAttr(namespace, attr),\n\t\tLangs:        sg.Params.Langs,\n\t\tReverse:      reverse,\n\t\tSrcFunc:      srcFunc,\n\t\tAfterUid:     sg.Params.AfterUID,","sourceCodeStart":935,"sourceCodeEnd":971,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/query.go#L935-L971","documentation":"Dgraph wraps any failure that occurs while computing the sort order (derived from the namespace) and pagination parameters for a query subgraph. The message 'While ordering and paginating' is a Wrapf context around an underlying error, so the real cause is in the wrapped inner error. It is thrown in query processing after calculatePaginationParams succeeded but ExtractNamespace from the request context failed.","triggerScenarios":"Calling a query (e.g. via /query endpoint with ordering/pagination) when the gRPC request context lacks a valid namespace header (e.g. X-Dgraph-Namespace missing/invalid in multi-namespace / Enterprise ACL setups), or the namespace extraction API errors on the context.","commonSituations":"Multi-namespace (Enterprise) deployments where the client does not send the namespace header; older client SDKs not setting namespace metadata; requests forwarded through a proxy that strips gRPC metadata.","solutions":["Inspect the inner wrapped error to identify the actual namespace extraction failure","Ensure the client sends a valid X-Dgraph-Namespace gRPC metadata header matching an existing namespace","Upgrade client SDK to a version that supports namespaces","If not using Enterprise multi-namespace, verify the server version matches client expectations"],"exampleFix":"// before (Go client, no namespace)\nctx := context.Background()\n// after\nmd := metadata.Pairs(\"X-Dgraph-Namespace\", \"1\")\nctx := metadata.NewOutgoingContext(context.Background(), md)","handlingStrategy":"try-catch","validationCode":"// Go client: ensure namespace metadata present before querying\nif nsHeader == \"\" {\n    return errors.New(\"X-Dgraph-Namespace metadata must be set for multi-namespace clusters\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := dg.NewReadOnlyTxn().Query(ctx, q)\nif err != nil {\n    if strings.Contains(err.Error(), \"While ordering and paginating\") {\n        // inspect wrapped cause: namespace extraction failed\n        return fmt.Errorf(\"namespace/pagination failure: %w\", err)\n    }\n    return err\n}","preventionTips":["Always set X-Dgraph-Namespace metadata when connecting to Enterprise multi-namespace clusters","Use a shared context-builder that injects namespace metadata consistently","Keep client SDK version aligned with server version","Test query paths against a multi-namespace environment before release"],"tags":["dgraph","grpc","pagination","namespace"],"backgroundTag":"missing-grpc-namespace-metadata","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}