dgraph-io/dgraph · error
While ordering and paginating
Error message
While ordering and paginating
What it means
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.
Source
Thrown at query/query.go:953
srcFunc.IsCount = sg.SrcFunc.IsCount
for _, arg := range sg.SrcFunc.Args {
srcFunc.Args = append(srcFunc.Args, arg.Value)
if arg.IsValueVar {
return nil, errors.Errorf("Unsupported use of value var")
}
}
}
// If the lang is set to *, query all the languages.
if len(sg.Params.Langs) == 1 && sg.Params.Langs[0] == "*" {
sg.Params.ExpandAll = true
}
// first is to limit how many results we want.
first, offset := calculatePaginationParams(sg)
ns, err := x.ExtractNamespace(ctx)
if err != nil {
return nil, errors.Wrapf(err, "While ordering and paginating")
}
orderParams := sg.createOrderForTask(ns)
sortMsg := &pb.SortMessage{
Order: orderParams,
UidMatrix: sg.uidMatrix,
Offset: int32(sg.Params.Offset),
Count: int32(sg.Params.Count),
ReadTs: sg.ReadTs,
}
out := &pb.Query{
ReadTs: sg.ReadTs,
Cache: int32(sg.Cache),
Attr: x.NamespaceAttr(namespace, attr),
Langs: sg.Params.Langs,
Reverse: reverse,
SrcFunc: srcFunc,
AfterUid: sg.Params.AfterUID,View on GitHub (pinned to 759e242be6)
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
Example fix
// before (Go client, no namespace)
ctx := context.Background()
// after
md := metadata.Pairs("X-Dgraph-Namespace", "1")
ctx := metadata.NewOutgoingContext(context.Background(), md) Defensive patterns
Strategy: try-catch
Validate before calling
// Go client: ensure namespace metadata present before querying
if nsHeader == "" {
return errors.New("X-Dgraph-Namespace metadata must be set for multi-namespace clusters")
} Try / catch
resp, err := dg.NewReadOnlyTxn().Query(ctx, q)
if err != nil {
if strings.Contains(err.Error(), "While ordering and paginating") {
// inspect wrapped cause: namespace extraction failed
return fmt.Errorf("namespace/pagination failure: %w", err)
}
return err
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- while calling MovePredicate
- While upserting user with id %s
- UpdateExtSnapshotStreamingStateRequest must not be nil
- UpdateExtSnapshotStreamingStateRequest cannot have both Star
- While processing query
AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01).
Data as JSON: /api/errors/e45903765689af05.
Report an issue: GitHub.