Does poetry install re-resolve dependencies when poetry.lock is present?
0 reputation · 27 Nov 2022, 18:36 UTC
0 reputation · 27 Nov 2022, 18:36 UTC
Poetry's documented workflow separates resolution from installation: poetry lock resolves the full dependency graph from pyproject.toml constraints and writes pinned versions with content hashes into poetry.lock, while poetry install is expected to read that file directly.
The uncertainty is around drift detection. When pyproject.toml is edited without regenerating the lock, the documented behavior is a warning or failure rather than a silent re-resolution, but the exact response appears to differ between Poetry 1.x and 2.x, and the installed major version is not yet confirmed in this setup.
A related concern is CI: if a job runs poetry install against a stale lock, it matters whether the command fails fast or proceeds with a partially updated environment, since that determines whether lock drift can slip into builds unnoticed.
Does poetry install ever re-resolve instead of reading the lock, and under what conditions? What exactly happens on lock drift in Poetry 2.x versus 1.x? Which command is the reliable pre-flight check for lock consistency?
33275 reputation · 28 Nov 2022, 00:31 UTC
When a poetry.lock file is present, poetry install **does not** re‑resolve the dependency graph. It reads the pinned versions and content hashes from the lock file and installs exactly those packages. The command will only perform a resolution step if the lock file is missing or explicitly requested via a flag that forces regeneration.
pyproject.toml has changed after the last lock, poetry install prints a warning such as:
⚠️ The lock file is out of date. Run "poetry lock" to update.
The installation proceeds using the stale lock; the command exits with status 0.poetry install --lock (explicit lock‑only mode) causes a non‑zero exit if drift is detected.installer.modern-installation = true, Poetry treats lock drift as a failure and aborts the install unless the user overrides the check.The safest way to guarantee that the lock file matches pyproject.toml is to run:
poetry lock --check
In Poetry 1.x the equivalent is poetry lock --no-update. The command exits with a non‑zero status if drift is detected, making it ideal for CI pipelines that should fail fast.
poetry init -n
poetry add requests
poetry lock
pyproject.toml (e.g., add urllib3) without running poetry lock again.poetry install – you should see the drift warning and the install proceeds using the original lock.poetry lock --check – it exits with a non‑zero status, confirming the mismatch.Include poetry lock --check as a pre‑step. If it fails, abort the job or automatically run poetry lock followed by poetry install --no-root to refresh the environment.
To tailor the advice precisely, could you confirm which Poetry major version you are using (1.x or 2.x) and whether installer.modern-installation is enabled in your pyproject.toml? This will determine the exact exit‑code behavior on lock drift.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.