{"id":"1781c3d5080440bb","repo":"python-poetry/poetry","slug":"the-lock-file-is-not-compatible-with-the-current-v-1781c3","errorCode":null,"errorMessage":"The lock file is not compatible with the current version of Poetry.\nUpgrade Poetry to be able to read the lock file or, alternatively, regenerate the lock file with the `poetry lock` command.","messagePattern":"The lock file is not compatible with the current version of Poetry\\.\nUpgrade Poetry to be able to read the lock file or, alternatively, regenerate the lock file with the `poetry lock` command\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/poetry/packages/locker.py","lineNumber":379,"sourceCode":"        metadata = lock_data[\"metadata\"]\n        if \"lock-version\" not in metadata:\n            raise RuntimeError(\n                \"The lock file is not compatible with the current version of Poetry.\\n\"\n                \"Regenerate the lock file with the `poetry lock` command.\"\n            )\n        lock_version = Version.parse(metadata[\"lock-version\"])\n        current_version = Version.parse(self._VERSION)\n        accepted_versions = parse_constraint(self._READ_VERSION_RANGE)\n        lock_version_allowed = accepted_versions.allows(lock_version)\n        if lock_version_allowed and current_version < lock_version:\n            logger.warning(\n                \"The lock file might not be compatible with the current version of\"\n                \" Poetry.\\nUpgrade Poetry to ensure the lock file is read properly or,\"\n                \" alternatively, regenerate the lock file with the `poetry lock`\"\n                \" command.\"\n            )\n        elif not lock_version_allowed:\n            raise RuntimeError(\n                \"The lock file is not compatible with the current version of Poetry.\\n\"\n                \"Upgrade Poetry to be able to read the lock file or, alternatively, \"\n                \"regenerate the lock file with the `poetry lock` command.\"\n            )\n\n        return lock_data\n\n    def _get_locked_package(\n        self, info: dict[str, Any], with_dependencies: bool = True\n    ) -> Package:\n        source = info.get(\"source\", {})\n        source_type = source.get(\"type\")\n        url = source.get(\"url\")\n        if source_type in [\"directory\", \"file\"]:\n            url = self.lock.parent.joinpath(url).resolve().as_posix()\n\n        name = info[\"name\"]\n        package = Package(","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/packages/locker.py#L361-L397","documentation":"Raised by Locker._get_lock_data() when metadata['lock-version'] parses but falls outside the accepted read range (_READ_VERSION_RANGE = '>=1,<3'). The lockfile was written by a Poetry whose schema is too new (or too old) for this Poetry build to read safely. The fix is either to upgrade Poetry or to regenerate the lockfile with the installed version.","triggerScenarios":"A teammate or CI image generated poetry.lock with Poetry 2.x producing lock-version 3.x (or vice-versa with a 0.x file), then you open the project with a Poetry whose _VERSION (2.1) and read range cannot accept it. Any locked read triggers it.","commonSituations":"Mixed Poetry versions across a team (some on 1.8, some on 2.x); CI pinned to an older Poetry while devs use newer; upgrading one machine but not others; lock-version bumped in a newer minor release.","solutions":["Upgrade Poetry to a version whose read range covers the lockfile's lock-version (`poetry self update`).","Alternatively regenerate the lockfile with your installed Poetry: `poetry lock`.","Align the whole team and CI on a single Poetry version to stop the schema churn.","Check `poetry --version` on every environment and pin it (e.g. via pipx, the official installer, or a pyproject build-requires)."],"exampleFix":"// before: lock-version 3.0 read by Poetry supporting <3\n# [metadata]\n# lock-version = \"3.0\"\n\n// after (option A — upgrade reader)\n$ poetry self update\n// after (option B — regenerate with current Poetry)\n$ poetry lock","handlingStrategy":"validation","validationCode":"from poetry.core.constraints.version import Version, parse_constraint\nimport tomllib\nfrom pathlib import Path\n\nREAD_RANGE = parse_constraint(\">=1,<3\")\n\ndef lockfile_version_compatible(path: Path) -> bool:\n    with path.open(\"rb\") as f:\n        lv = tomllib.load(f).get(\"metadata\", {}).get(\"lock-version\")\n    return bool(lv) and READ_RANGE.allows(Version.parse(lv))","typeGuard":null,"tryCatchPattern":"from poetry.packages import Locker\n\ntry:\n    locker._get_lock_data()\nexcept RuntimeError as e:\n    if \"not compatible with the current version\" in str(e):\n        # either upgrade poetry or regenerate lock\n        ...","preventionTips":["Standardise the whole team and CI on one Poetry version.","Re-run `poetry lock` after every Poetry upgrade.","Check `poetry --version` and the lock-version in a CI matrix step.","Communicate Poetry upgrades to all collaborators before they pull the new lockfile."],"tags":["lockfile","version","compatibility","upgrade"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}