{"record":{"id":"3fea09c99b7430ea","repo":"tiangolo/fastapi","slug":"new-version-version-must-be-greater-than-current","errorCode":null,"errorMessage":"New version {version} must be greater than current version {current_version}","messagePattern":"New version (.+?) must be greater than current version (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"scripts/prepare_release.py","lineNumber":56,"sourceCode":"            f\"Expected exactly one __version__ assignment in {version_file}, \"\n            f\"found {len(matches)}\"\n        )\n    return matches[0].group(1)\n\n\ndef bump_version(version: str, bump: BumpType) -> str:\n    major, minor, patch = parse_version(version)\n    if bump == \"major\":\n        return f\"{major + 1}.0.0\"\n    if bump == \"minor\":\n        return f\"{major}.{minor + 1}.0\"\n    return f\"{major}.{minor}.{patch + 1}\"\n\n\ndef update_version_file(content: str, version: str, version_file: Path) -> str:\n    current_version = get_current_version(content, version_file)\n    if parse_version(version) <= parse_version(current_version):\n        raise RuntimeError(\n            f\"New version {version} must be greater than current version {current_version}\"\n        )\n    return VERSION_PATTERN.sub(f'__version__ = \"{version}\"', content, count=1)\n\n\ndef update_release_notes(\n    content: str, version: str, release_date: date, release_notes_file: Path\n) -> str:\n    if not content.startswith(RELEASE_NOTES_HEADER):\n        raise RuntimeError(\n            f\"{release_notes_file} must start with {RELEASE_NOTES_HEADER!r}\"\n        )\n    if re.search(rf\"^## {re.escape(version)}(?: \\([^)]+\\))?$\", content, re.M):\n        raise RuntimeError(f\"Release notes already contain a section for {version}\")\n\n    latest_header = f\"{RELEASE_NOTES_HEADER}{LATEST_CHANGES_HEADER}\\n\"\n    if not content.startswith(latest_header):\n        raise RuntimeError(f\"{release_notes_file} must start with {latest_header!r}\")","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/tiangolo/fastapi/blob/3e8d1526d83a90aaf7d6eb6dc682bf150f180b25/scripts/prepare_release.py#L38-L74","documentation":"Raised by update_version_file() in scripts/prepare_release.py:56 when the requested new version is not strictly greater than the current version (parse_version(version) <= parse_version(current_version) at scripts/prepare_release.py:55). Releases must move forward; equal or lower versions are rejected to prevent regressions in published artifacts and PyPI.","triggerScenarios":"Calling prepare with a version bump that resolves to <= current, or directly calling update_version_file with a lower/equal version. Can happen if the version file was already bumped ahead of the requested bump.","commonSituations":"Someone manually bumped __version__ before running prepare, so the computed bump (e.g. patch) is not greater than the new current. Two concurrent release attempts race. A hotfix version was passed manually below the released version.","solutions":["Check the current version: python scripts/prepare_release.py current-version --version-file <path>.","Use a larger bump type (minor instead of patch) if the file is already ahead.","Reset the version file to the last released version if it was bumped prematurely."],"exampleFix":"# before — version file already at 1.2.3, asking for patch bump -> 1.2.3 (not greater)\n__version__ = \"1.2.3\"\n# after — bump minor or reset first\n__version__ = \"1.2.2\"  # then run: prepare minor","handlingStrategy":"validation","validationCode":"def new_gt_current(new: str, current: str) -> bool:\n    def t(v):\n        a, b, c = v.split(\".\")\n        return (int(a), int(b), int(c))\n    return t(new) > t(current)","typeGuard":null,"tryCatchPattern":"try:\n    new_content = update_version_file(content, version, version_file)\nexcept RuntimeError as e:\n    raise SystemExit(f\"Refusing to downgrade: {e}\") from e","preventionTips":["Run prepare from a clean version file at the last released version.","Avoid concurrent release runs that both bump the same file.","Check current-version before invoking prepare."],"tags":["release","versioning","validation"],"backgroundTag":null,"analyzedSha":"3e8d1526d83a90aaf7d6eb6dc682bf150f180b25","analyzedAt":"2026-08-11T02:34:52.986Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}