{"record":{"id":"e167c39befc60268","repo":"dgraph-io/dgraph","slug":"while-processing-query","errorCode":null,"errorMessage":"While processing query","messagePattern":"While processing query","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/query.go","lineNumber":3060,"sourceCode":"\tMetrics    map[string]uint64\n}\n\n// Process handles a query request.\nfunc (req *Request) Process(ctx context.Context) (er ExecutionResult, err error) {\n\terr = req.ProcessQuery(ctx)\n\tif err != nil {\n\t\treturn er, err\n\t}\n\ter.Subgraphs = req.Subgraphs\n\t// calculate metrics.\n\tmetrics := make(map[string]uint64)\n\tfor _, sg := range er.Subgraphs {\n\t\tcalculateMetrics(sg, metrics)\n\t}\n\ter.Metrics = metrics\n\tnamespace, err := x.ExtractNamespace(ctx)\n\tif err != nil {\n\t\treturn er, errors.Wrapf(err, \"While processing query\")\n\t}\n\tschemaProcessingStart := time.Now()\n\tif req.DqlQuery.Schema != nil {\n\t\tpreds := x.NamespaceAttrList(namespace, req.DqlQuery.Schema.Predicates)\n\t\treq.DqlQuery.Schema.Predicates = preds\n\t\tif er.SchemaNode, err = worker.GetSchemaOverNetwork(ctx, req.DqlQuery.Schema); err != nil {\n\t\t\treturn er, errors.Wrapf(err, \"while fetching schema\")\n\t\t}\n\t\ttypeNames := x.NamespaceAttrList(namespace, req.DqlQuery.Schema.Types)\n\t\treq.DqlQuery.Schema.Types = typeNames\n\t\tif er.Types, err = worker.GetTypes(ctx, req.DqlQuery.Schema); err != nil {\n\t\t\treturn er, errors.Wrapf(err, \"while fetching types\")\n\t\t}\n\t}\n\n\tif !x.IsRootNsOperation(ctx) {\n\t\t// Filter the schema nodes for the given namespace.\n\t\ter.SchemaNode = filterSchemaNodeForNamespace(namespace, er.SchemaNode)","sourceCodeStart":3042,"sourceCodeEnd":3078,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/query.go#L3042-L3078","documentation":"After the query executes, Dgraph extracts the namespace (ACL/multi-tenancy) from the request context via x.ExtractNamespace. If the context lacks valid namespace information, the whole result is returned with this wrapped error. It is a multi-tenancy context problem, not a data problem.","triggerScenarios":"Sending a query without proper authentication/JWT that carries the namespace claim (e.g. missing X-Dgraph-AccessToken or Guardian/namespace user token), or a context whose namespace metadata was stripped between client and server.","commonSituations":"Enterprise multi-tenancy deployments where the client forgot to set the access token header, tokens expired, or a proxy stripped the header; also requests routed through tooling not propagating gRPC metadata.","solutions":["Attach a valid access token: send X-Dgraph-AccessToken header (HTTP) or the auth token in gRPC metadata","Log in via /login endpoint to obtain a JWT for the target namespace and refresh it before expiry","Verify the token includes the correct namespace claim for the queried tenant","Ensure proxies/gateways do not strip Dgraph auth headers/metadata"],"exampleFix":"// before\ncurl http://localhost:8080/query -XPOST -d '{ me(func: uid(0x1)) { name } }'\n// after\ncurl http://localhost:8080/query -XPOST -H 'X-Dgraph-AccessToken: <jwt>' -d '{ me(func: uid(0x1)) { name } }'","handlingStrategy":"validation","validationCode":"// Ensure a token with namespace claim is available before querying\nif accessToken == \"\" {\n    return errors.New(\"X-Dgraph-AccessToken required for multi-namespace cluster\")\n}","typeGuard":null,"tryCatchPattern":"resp, err := txn.Query(ctx, dql)\nif err != nil && strings.Contains(err.Error(), \"While processing query\") {\n    // refresh login token then retry once\n    if rerr := refreshLogin(ctx); rerr != nil { return rerr }\n    resp, err = txn.Query(ctx, dql)\n}","preventionTips":["Always call /login and attach the JWT when ACLs/multi-tenancy are enabled","Refresh tokens before expiry (schedule refresh at 80% of TTL)","Verify proxies preserve X-Dgraph-AccessToken and gRPC metadata"],"tags":["multi-tenancy","namespace","context","dgraph"],"backgroundTag":"missing-namespace-context","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}