{"record":{"id":"1abb42a910a2f07d","repo":"dgraph-io/dgraph","slug":"invalid-shortest-path-query","errorCode":null,"errorMessage":"Invalid shortest path query","messagePattern":"Invalid shortest path query","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"query/shortest.go","lineNumber":289,"sourceCode":"\t\texec = out\n\t}\n}\n\nfunc (sg *SubGraph) copyFiltersRecurse(otherSubgraph *SubGraph) {\n\t*sg = *otherSubgraph\n\tsg.Children = []*SubGraph{}\n\tsg.Filters = []*SubGraph{}\n\tfor _, fc := range otherSubgraph.Filters {\n\t\ttempChild := new(SubGraph)\n\t\ttempChild.copyFiltersRecurse(fc)\n\t\tsg.Filters = append(sg.Filters, tempChild)\n\t}\n}\n\nfunc runKShortestPaths(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) {\n\tvar err error\n\tif sg.Params.Alias != \"shortest\" {\n\t\treturn nil, errors.Errorf(\"Invalid shortest path query\")\n\t}\n\n\tnumPaths := sg.Params.NumPaths\n\tvar kroutes []route\n\tpq := make(priorityQueue, 0)\n\n\t// Initialize and push the source node.\n\tsrcNode := &queueItem{\n\t\tuid:  sg.Params.From,\n\t\tcost: 0,\n\t\thop:  0,\n\t\tpath: route{route: &[]pathInfo{{uid: sg.Params.From}}},\n\t}\n\theap.Push(&pq, srcNode)\n\n\tnumHops := 0\n\tmaxHops := math.MaxInt32\n\tif sg.Params.ExploreDepth != nil {","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/query/shortest.go#L271-L307","documentation":"runKShortestPaths validates that the SubGraph it received was actually produced by a `shortest` alias block; if sg.Params.Alias != \"shortest\" it refuses to run the Yen-style k-shortest-path algorithm. This is an internal consistency guard — the k-shortest path runner was handed a query fragment that is not a shortest-path block.","triggerScenarios":"An internal dispatch reaching runKShortestPaths with a SubGraph whose Params.Alias is not \"shortest\"; effectively only occurs from a bug, altered query pipeline, or hand-crafted internal calls — ordinary DQL users should not hit it via valid `shortest` queries.","commonSituations":"Custom forks or patched Dgraph builds invoking the query path differently; regression from a Dgraph version where shortest-path routing changed; programmatic construction of SubGraph params in tests/tools.","solutions":["Verify the query uses a proper `shortest` block with `to:` and no altered alias handling.","Upgrade/rollback Dgraph to a release where shortest-path dispatch is intact (check release notes).","Check any middleware or forks that rewrite query params/aliases before execution.","If reproducible on vanilla Dgraph, report with the query and version."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await txn.Query(ctx, q);\n} catch (e) {\n  if (String(e).includes('Invalid shortest path query')) {\n    // ensure query uses a `shortest` block; retry or report\n  }\n  throw e;\n}","preventionTips":["Always write shortest-path queries with a proper `shortest` block: shortest(to: uid(...)) { ... }","Run unpatched, supported Dgraph releases","Don't hand-craft SubGraph params in internal tooling without matching the alias contract"],"tags":["dgraph","shortest-path","internal-validation"],"backgroundTag":"invalid-shortest-path-query","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}