Skip to content

Fix repeated updates caused by stale VCS source directories - #11058

Open
aprylewu wants to merge 2 commits into
python-poetry:mainfrom
aprylewu:fix/ignore-stale-vcs-source-directory
Open

Fix repeated updates caused by stale VCS source directories#11058
aprylewu wants to merge 2 commits into
python-poetry:mainfrom
aprylewu:fix/ignore-stale-vcs-source-directory

Conversation

@aprylewu

@aprylewu aprylewu commented Sep 12, 2026

Copy link
Copy Markdown

Pull Request Check List

Resolves: #7089

  • Added tests for changed code.
  • Updated documentation for changed code. N/A: fixes installed-package detection without changing the public interface.

A checkout left in <venv>/src/<name> after switching from a Git dependency to an index release is currently enough for Poetry to classify the installed release as a Git package. This makes subsequent installs repeatedly schedule an update even when the installed version is already correct.

Stop treating the presence of that source directory alone as installation metadata. Keep the existing .pth, source-local egg-info, and PEP 610 detection paths. The checkout is left intact.

The new regression creates actual temporary dist-info metadata and a source directory, with and without a .pth link. On the original code, the unlinked case fails because it is incorrectly classified as Git; the linked case passes.

Validation on macOS / Python 3.13.5:

  • pytest -n 0 tests/repositories/test_installed_repository.py: 29 passed, including existing .pth, legacy egg-info, and PEP 610 cases.
  • pytest -n 0 tests/puzzle/test_transaction.py: 89 passed.
  • An independent probe using actual local Git repositories (no Git-info mock) passed 8 scenarios: the stale checkout now yields an "Already installed" skip instead of an update, while valid .pth, legacy egg-info, and PEP 610 sources retain their original metadata.
  • mypy: no issues in 380 source files.
  • pre-commit run --files src/poetry/repositories/installed_repository.py tests/repositories/test_installed_repository.py: all applicable checks passed.

The unit tests use temporary metadata and existing Git-info fixtures. I also ran an offline CLI reproduction of #2921 using a local Git dependency at a fixed package version: advancing the branch updates the imported module, lock file, and PEP 610 commit ID, both with normal metadata and after removing the origin metadata. Subsequent poetry install runs skip the dependency. Poetry and poetry-core were tested from current main; the entire project test suite was not run.

Compatibility with #3867: that PR introduced the directory fallback removed here. Existing installs without .pth or direct_url.json lose the inferred Git classification. A Git requirement then schedules a reinstall even at the same version; the executor writes origin metadata so later installs can skip it. This can cause a one-time reinstall for such legacy environments. Four new cases cover unchanged/changed Git revisions with and without origin metadata; .pth, source-local egg-info, and PEP 610 discovery remain supported.

Prepared with OpenAI Codex assistance and independently reviewed by another Codex agent.

A checkout left under the environment's src directory does not establish
that the installed distribution still comes from Git. After switching to
an index release, this fallback misclassifies its source and schedules an
update on every install. Require the existing .pth, egg-info or PEP 610
metadata paths instead, without removing the checkout.

Fixes python-poetry#7089

Signed-off-by: Mingyang Wu <129849514+aprylewu@users.noreply.github.com>
Assisted-by: OpenAI Codex
sourcery-ai[bot]
sourcery-ai Bot previously approved these changes Sep 12, 2026

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@dimbleby

Copy link
Copy Markdown
Contributor

This reverses #3867 - presumably it breaks whatever that fixed

Check same-version Git revision changes through installed package discovery
and transaction planning. Cover PEP 610 installs and legacy environments
without .pth or direct_url.json, including the one-time reinstall needed
to recover origin metadata.

Signed-off-by: Mingyang Wu <129849514+aprylewu@users.noreply.github.com>
Assisted-by: OpenAI Codex
@aprylewu

Copy link
Copy Markdown
Author

Yes, #3867 introduced exactly this fallback; I should have checked that history before submitting.

I checked #2921 and added four cases in 7e79226 covering same-version Git revision changes, with and without direct_url.json and no .pth. I also ran the actual CLI against a local Git repository: after advancing the branch, the imported module, lock file and recorded commit all update, including when the previous origin metadata is missing. The next poetry install skips the dependency. All 118 related tests, mypy and pre-commit pass.

There is a compatibility change: a metadata-less legacy install is no longer inferred to be Git from the checkout directory. A Git requirement triggers one reinstall, after which the executor writes PEP 610 metadata and subsequent installs skip it. I verified that unchanged-commit migration too and documented this one-time reinstall in the PR description. Existing .pth, source-local egg-info and PEP 610 paths remain supported.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery assessment

Approved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(🐞) poetry install keeps installing things that are already installed, when they were previously a git dependency

2 participants