Skip to content

fix(version): correct semantic version ordering#197

Open
HetCreep wants to merge 1 commit into
fa0311:masterfrom
HetCreep:fix/version-comparison
Open

fix(version): correct semantic version ordering#197
HetCreep wants to merge 1 commit into
fa0311:masterfrom
HetCreep:fix/version-comparison

Conversation

@HetCreep

@HetCreep HetCreep commented Jun 1, 2026

Copy link
Copy Markdown

Problem

Version.__lt__ / __gt__ compare each field with an independent or, so the result is wrong whenever a lower place-value differs in the opposite direction:

Version("v6.0.0") < Version("v5.10.0")
# major: 6 < 5  -> False
# minor: 0 < 10 -> True
# => returns True  (wrong: 6.0.0 is NOT less than 5.10.0)

Impact

static/loder.py gates config migration on this comparison:

if version < Version("v5.5.2"):

A user whose last_version is e.g. v5.10.0 evaluates 5.10.0 < 5.5.2 as True (patch 0 < 2), so an already-migrated config can be migrated again. Any ordering check on Version is affected (__le__/__ge__ delegate to these).

Fix

Compare the (major, minor, patch) tuples, which Python orders lexicographically - exactly the semantic-version rule. Two-line change; __le__/__ge__ are fixed transitively.

def __lt__(self, other: "Version"):
    return (self.major, self.minor, self.patch) < (other.major, other.minor, other.patch)

def __gt__(self, other: "Version"):
    return (self.major, self.minor, self.patch) > (other.major, other.minor, other.patch)

`__lt__`/`__gt__` compared each field with independent `or`, so ordering
was wrong whenever a lower place-value differed in the opposite direction:

    Version("v6.0.0") < Version("v5.10.0")
    # major 6 < 5 -> False, minor 0 < 10 -> True  => returns True (wrong)

Compare the (major, minor, patch) tuples instead, which Python orders
lexicographically — the correct semantic-version behaviour. `__le__`/`__ge__`
delegate to these and are fixed transitively.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants