dgraph-io/dgraph · error

error: `%s` must be less than `%s`

Error message

error: `%s` must be less than `%s`

What it means

The dgraph upgrade command validates that the --from version is strictly less than the --to version by comparing parsed version structs. This error is returned from validateAndParseInput (via run) when from >= to, meaning the requested upgrade range is invalid or reversed.

Source

Thrown at upgrade/upgrade.go:196

func validateAndParseInput() (*commandInput, error) {
	_, _, err := net.SplitHostPort(strings.TrimSpace(Upgrade.Conf.GetString(alpha)))
	if err != nil {
		return nil, formatAsFlagParsingError(alpha, err)
	}

	fromVersionParsed, err := parseVersionFromString(Upgrade.Conf.GetString(from))
	if err != nil {
		return nil, formatAsFlagParsingError(from, err)
	}

	toVersionParsed, err := parseVersionFromString(Upgrade.Conf.GetString(to))
	if err != nil {
		return nil, formatAsFlagParsingError(to, err)
	}

	if fromVersionParsed.Compare(toVersionParsed) != less {
		return nil, fmt.Errorf("error: `%s` must be less than `%s`", from, to)
	}

	return &commandInput{fromVersion: fromVersionParsed, toVersion: toVersionParsed}, nil
}

func formatAsFlagParsingError(flag string, err error) error {
	return fmt.Errorf("error parsing flag `%s`: %w", flag, err)
}

// parseVersionFromString parses a version given as string to internal representation.
// Some examples for input and output:
//  1. input : v1.2.2
//     output: &version{major: 1, minor: 2, patch: 2}, nil
//  2. input : v20.03.0-beta.20200320
//     output: &version{major: 20, minor: 3, patch: 0}, nil
//  3. input : 1.2.2
//     output: nil, error
//  4. input : v1.2.2s

View on GitHub (pinned to 759e242be6)

Solutions

  1. Swap the flag values so the older version is --from and the newer version is --to.
  2. Use valid semver values prefixed with v, e.g. dgraph upgrade offline -f v20.11.0 -t v21.03.0.
  3. If you intended a downgrade, use the correct restore/backup workflow instead — this command only upgrades forward.
  4. Check scripts for swapped variables in the flag invocation.

Example fix

// before
dgraph upgrade offline -f v21.03.0 -t v20.11.0
// after
dgraph upgrade offline -f v20.11.0 -t v21.03.0
Defensive patterns

Strategy: validation

Validate before calling

func validUpgradeRange(from, to string) bool {
	// vMAJOR.MINOR.PATCH
	re := regexp.MustCompile(`^v\d+\.\d+\.\d+$`)
	if !re.MatchString(from) || !re.MatchString(to) { return false }
	cmp := func(v string) int {
		p := strings.Split(strings.TrimPrefix(v, "v"), ".")
		a, _ := strconv.Atoi(p[0]); b, _ := strconv.Atoi(p[1]); c, _ := strconv.Atoi(p[2])
		return a*10000 + b*100 + c
	}
	return cmp(from) < cmp(to)
}
// use: if !validUpgradeRange(fromVer, toVer) { fix flags before running }

Prevention

When it happens

Trigger: Running dgraph upgrade with --from greater than or equal to --to, e.g. --from v21.03.0 --to v20.11.0, or equal versions --from v21.03.0 --to v21.03.0.

Common situations: Typos in version flags, scripting mistakes where variables are swapped, attempting a downgrade (not supported by this command).

Related errors


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