{"id":"7b03d20d06fe8568","repo":"python-poetry/poetry","slug":"the-lock-file-does-not-have-a-metadata-entry-rege","errorCode":null,"errorMessage":"The lock file does not have a metadata entry.\nRegenerate the lock file with the `poetry lock` command.","messagePattern":"The lock file does not have a metadata entry\\.\nRegenerate the lock file with the `poetry lock` command\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"src/poetry/packages/locker.py","lineNumber":356,"sourceCode":"            # of the [tool.poetry] section at top level!\n            relevant_content = relevant_poetry_content\n\n        return sha256(json.dumps(relevant_content, sort_keys=True).encode()).hexdigest()\n\n    def _get_lock_data(self) -> dict[str, Any]:\n        if not self.lock.exists():\n            raise RuntimeError(\"No lockfile found. Unable to read locked packages\")\n\n        with self.lock.open(\"rb\") as f:\n            try:\n                lock_data = tomllib.load(f)\n            except tomllib.TOMLDecodeError as e:\n                raise RuntimeError(f\"Unable to read the lock file ({e}).\")\n\n        # if the lockfile doesn't contain a metadata section at all,\n        # it probably needs to be rebuilt completely\n        if \"metadata\" not in lock_data:\n            raise RuntimeError(\n                \"The lock file does not have a metadata entry.\\n\"\n                \"Regenerate the lock file with the `poetry lock` command.\"\n            )\n\n        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,\"","sourceCodeStart":338,"sourceCodeEnd":374,"githubUrl":"https://github.com/python-poetry/poetry/blob/92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54/src/poetry/packages/locker.py#L338-L374","documentation":"Raised by Locker._get_lock_data() when the parsed lockfile dict has no top-level 'metadata' key. The metadata section is mandatory in every Poetry lockfile (it records lock-version and content-hash); its absence means the file is not a real Poetry lockfile or is from a format too old to use. Poetry refuses to guess and asks you to regenerate.","triggerScenarios":"Any locked-packages read on a poetry.lock that is valid TOML but missing the [metadata] table — e.g. a hand-authored stub, a file copied from another tool, or a lockfile generated by a very old pre-metadata Poetry version.","commonSituations":"Migrating from extremely old Poetry (<1.0) where the lock schema differed; committing a placeholder poetry.lock; a different tool (pip-tools, pdm) wrote a file named poetry.lock.","solutions":["Run `poetry lock` to regenerate a standards-compliant poetry.lock with the metadata table.","If regenerating is undesirable, inspect poetry.lock to confirm it is genuinely a Poetry lockfile and not from another tool.","Upgrade Poetry to the latest stable release before locking, so the generated metadata is current."],"exampleFix":"// before: poetry.lock with no [metadata] section\n[[package]]\nname = \"click\"\nversion = \"8.1.0\"\n\n// after\n$ poetry lock","handlingStrategy":"validation","validationCode":"import tomllib\nfrom pathlib import Path\n\ndef lockfile_has_metadata(path: Path) -> bool:\n    with path.open(\"rb\") as f:\n        data = tomllib.load(f)\n    return \"metadata\" in data","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always generate poetry.lock with a current Poetry version.","Do not copy lockfiles from other tools (pdm, pip-tools) under the poetry.lock name.","After any lockfile manipulation, verify the [metadata] table is intact.","Pin the Poetry version in CI to avoid schema drift."],"tags":["lockfile","metadata","version"],"analyzedSha":"92b74dcfe348d0e01e14d40d6c1fa47a4ee04a54","analyzedAt":"2026-08-04T20:33:34.072Z","schemaVersion":2}