Poetry.lock vs pyproject.toml: Safe rollback after schema change?
0 reputation · 08 Feb 2021, 19:18 UTC
0 reputation · 08 Feb 2021, 19:18 UTC
The goal is to revert a project to a known good dependency state after the schema in pyproject.toml has been altered. In practice, this means restoring an older poetry.lock and invoking poetry install to re‑install the exact package hashes recorded in that lockfile.
Key constraints:
pyproject.toml without re‑running poetry lock can leave the resolver in a partially resolved state.poetry install after replacing the lockfile may trigger ResolutionImpossible errors if the newer constraints conflict with the old lockfile.Unresolved questions:
poetry.lock and running poetry install always re‑establish the exact environment, regardless of the Poetry version?pyproject.toml has been updated?35275 reputation · 09 Feb 2021, 06:15 UTC
Restoring an older poetry.lock and running poetry install will reproduce the exact previous environment only if two conditions are met:
poetry.lock was generated by the same major Poetry version that will perform the install (1.x or 2.x).pyproject.toml still satisfies all constraints recorded in that lockfile.When either condition fails, the resolver will refuse to install and emit a ResolutionImpossible or format‑error message. Thus, a blind restoration is not guaranteed to succeed.
poetry install will fetch.pyproject.toml without re‑running poetry lock can leave the lockfile out of sync with the constraints.pyproject.toml now requires a newer version of a package than the lockfile records, the resolver will report that the lockfile is incompatible.pyproject.toml so you can restore it if needed: cp pyproject.toml pyproject.toml.bak.poetry lock --check
If the command exits cleanly, the lockfile satisfies the current constraints. If it fails, you must either restore the pyproject.toml that matched the lockfile or regenerate the lockfile with the current Poetry version.poetry install.
After installation, you can double‑check that the environment matches the intended state by running:
poetry show --tree
poetry export -f requirements.txt > requirements.txt
These outputs should be identical to those from the original snapshot.
To decide whether you can skip step 3 (the compatibility check) or need to revert pyproject.toml, we need to know which Poetry major version produced the lockfile you want to restore.
Could you tell us whether the lockfile was generated by Poetry 1.x or 2.x?
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.