dgraph-io/dgraph · error

Invalid shortest path query

Error message

Invalid shortest path query

What it means

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.

Source

Thrown at query/shortest.go:289

		exec = out
	}
}

func (sg *SubGraph) copyFiltersRecurse(otherSubgraph *SubGraph) {
	*sg = *otherSubgraph
	sg.Children = []*SubGraph{}
	sg.Filters = []*SubGraph{}
	for _, fc := range otherSubgraph.Filters {
		tempChild := new(SubGraph)
		tempChild.copyFiltersRecurse(fc)
		sg.Filters = append(sg.Filters, tempChild)
	}
}

func runKShortestPaths(ctx context.Context, sg *SubGraph) ([]*SubGraph, error) {
	var err error
	if sg.Params.Alias != "shortest" {
		return nil, errors.Errorf("Invalid shortest path query")
	}

	numPaths := sg.Params.NumPaths
	var kroutes []route
	pq := make(priorityQueue, 0)

	// Initialize and push the source node.
	srcNode := &queueItem{
		uid:  sg.Params.From,
		cost: 0,
		hop:  0,
		path: route{route: &[]pathInfo{{uid: sg.Params.From}}},
	}
	heap.Push(&pq, srcNode)

	numHops := 0
	maxHops := math.MaxInt32
	if sg.Params.ExploreDepth != nil {

View on GitHub (pinned to 759e242be6)

Solutions

  1. Verify the query uses a proper `shortest` block with `to:` and no altered alias handling.
  2. Upgrade/rollback Dgraph to a release where shortest-path dispatch is intact (check release notes).
  3. Check any middleware or forks that rewrite query params/aliases before execution.
  4. If reproducible on vanilla Dgraph, report with the query and version.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await txn.Query(ctx, q);
} catch (e) {
  if (String(e).includes('Invalid shortest path query')) {
    // ensure query uses a `shortest` block; retry or report
  }
  throw e;
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/1abb42a910a2f07d. Report an issue: GitHub.