Skip to content

fix(installer): re-solve directory dependencies in update, add and remove - #11293

Open
APX403 wants to merge 1 commit into
python-poetry:mainfrom
APX403:fix-update-directory-dependencies
Open

APX403 wants to merge 1 commit into
python-poetry:mainfrom
APX403:fix-update-directory-dependencies

Conversation

@APX403

@APX403 APX403 commented Nov 28, 2026

Copy link
Copy Markdown

Pull Request Check List

Resolves: #5111

  • Added tests for changed code.
  • Updated documentation for changed code.

With the chain from the issue (lib_c depends on lib_b by path, and lib_b on lib_a), a dependency added to lib_a is left out of the lock file of lib_c by poetry add, poetry remove, and poetry update of any package other than lib_a. These commands keep the locked metadata of lib_a, so poetry install does not install the new dependency and poetry check --lock still passes. Only poetry lock or a full poetry update picks it up.

Since #6843, poetry lock re-solves every locked directory dependency, because the lock file cannot tell whether its metadata changed. Installer._do_install() only passes the packages being updated as use_latest, so the solver keeps what the lock file says about every other directory dependency.

When only some packages are updated, the locked directory dependencies are now added to the whitelist as well. That way the solve for the environment also sees them when installer.re-resolve is enabled, and other locked packages keep their versions. Like poetry lock, these commands now read the metadata of every directory dependency, so they fail when the folder of one of them is missing instead of printing a warning.

…move

`poetry lock` always re-solves directory dependencies (python-poetry#6843), because the
lock file cannot tell whether their metadata changed. `poetry update
<package>`, `poetry add` and `poetry remove` only re-solved the requested
packages, so a dependency added to a path dependency was left out of the
lock file and was not installed.
@sourcery-ai

sourcery-ai Bot commented Nov 28, 2026

Copy link
Copy Markdown

Linked issues

Checked at commit c24bdd5

#5111 Transitive dependencies of path dependencies are not updated with `poetry update X` · 1 of 1 met

# Requirement Status Notes
1 Have poetry update some_package capture and update nested dependencies of path dependencies in the lock file. ✅ Met When a partial update has a whitelist, the change adds every locked directory dependency to it, so those packages are re-solved.

@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 found 3 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/poetry/installation/installer.py" line_range="238-239" />
<code_context>
+                    # determine if anything has changed (and the lock file contains
+                    # an invalid version).
+                    for pkg in locked_repository.packages:
+                        if pkg.source_type == "directory":
+                            self._whitelist.append(pkg.name)

             # Checking extras
</code_context>
<issue_to_address>
**Unchanged dependency backend executes**

When an attacker controls a locked directory dependency whose metadata requires its PEP 517 backend, and the user updates another package, `use_latest` causes the provider to reload that directory dependency; `PackageInfo.from_directory()` then calls `isolated_builder(...).metadata_path()`, executing its PEP 517 backend as the invoking user during an update of another package.

Avoid executing build backends for untouched directory dependencies, or make this additional execution an explicit, documented opt-in.
</issue_to_address>

### Comment 2
<location path="src/poetry/installation/installer.py" line_range="239" />
<code_context>
                 if not self._whitelist:
                     for pkg in locked_repository.packages:
                         self._whitelist.append(pkg.name)
+                else:
+                    # Always re-solve directory dependencies, otherwise we can't
</code_context>
<issue_to_address>
**Concurrent edits leave stale lock**

When a directory dependency’s metadata changes after the solver reads it but before execution and lock writing finish, `Solver` reads the directory’s dependency metadata while resolving, then `Executor` builds from the live path after it changes, so the new dependency is absent from the solved operations and the written lock file.

Resolve and build from a stable snapshot of each directory dependency, or detect metadata changes before writing the lock and retry the solve.
</issue_to_address>

### Comment 3
<location path="src/poetry/installation/installer.py" line_range="239" />
<code_context>
                 if not self._whitelist:
                     for pkg in locked_repository.packages:
                         self._whitelist.append(pkg.name)
+                else:
+                    # Always re-solve directory dependencies, otherwise we can't
</code_context>
<issue_to_address>
**Same-name packages update unexpectedly**

When the lock file has directory and non-directory variants with the same normalized package name, and the non-directory variant has a newer resolvable version, `Provider.get_locked()` skips locked packages by normalized name, so adding a directory package’s name to `use_latest` also bypasses a locked variant of that name from another source; the resolver selects a new variant and an unrelated package changes during the update.

Make the directory re-solve exemption source-specific so it does not bypass locked variants from other sources.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 3 findings to address first, and the installer now re-solves every locked directory dependency during a whitelisted operation, which can change the selected package and dependency set in the lockfile and installed environment. Reverting the code will not restore those changes automatically, but the lockfile can be regenerated and the environment reinstalled.

Blocking findings: src/poetry/installation/installer.py:239, src/poetry/installation/installer.py:239, src/poetry/installation/installer.py:239


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

Comment on lines +238 to +239
if pkg.source_type == "directory":
self._whitelist.append(pkg.name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Unchanged dependency backend executes

When an attacker controls a locked directory dependency whose metadata requires its PEP 517 backend, and the user updates another package, use_latest causes the provider to reload that directory dependency; PackageInfo.from_directory() then calls isolated_builder(...).metadata_path(), executing its PEP 517 backend as the invoking user during an update of another package.

Avoid executing build backends for untouched directory dependencies, or make this additional execution an explicit, documented opt-in.

Prompt for AI agents
In `src/poetry/installation/installer.py` at lines 238-239:

**Unchanged dependency backend executes**

When an attacker controls a locked directory dependency whose metadata requires its PEP 517 backend, and the user updates another package, `use_latest` causes the provider to reload that directory dependency; `PackageInfo.from_directory()` then calls `isolated_builder(...).metadata_path()`, executing its PEP 517 backend as the invoking user during an update of another package.

Avoid executing build backends for untouched directory dependencies, or make this additional execution an explicit, documented opt-in.

# an invalid version).
for pkg in locked_repository.packages:
if pkg.source_type == "directory":
self._whitelist.append(pkg.name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Concurrent edits leave stale lock

When a directory dependency’s metadata changes after the solver reads it but before execution and lock writing finish, Solver reads the directory’s dependency metadata while resolving, then Executor builds from the live path after it changes, so the new dependency is absent from the solved operations and the written lock file.

Resolve and build from a stable snapshot of each directory dependency, or detect metadata changes before writing the lock and retry the solve.

Prompt for AI agents
In `src/poetry/installation/installer.py` at line 239:

**Concurrent edits leave stale lock**

When a directory dependency’s metadata changes after the solver reads it but before execution and lock writing finish, `Solver` reads the directory’s dependency metadata while resolving, then `Executor` builds from the live path after it changes, so the new dependency is absent from the solved operations and the written lock file.

Resolve and build from a stable snapshot of each directory dependency, or detect metadata changes before writing the lock and retry the solve.

# an invalid version).
for pkg in locked_repository.packages:
if pkg.source_type == "directory":
self._whitelist.append(pkg.name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · Same-name packages update unexpectedly

When the lock file has directory and non-directory variants with the same normalized package name, and the non-directory variant has a newer resolvable version, Provider.get_locked() skips locked packages by normalized name, so adding a directory package’s name to use_latest also bypasses a locked variant of that name from another source; the resolver selects a new variant and an unrelated package changes during the update.

Make the directory re-solve exemption source-specific so it does not bypass locked variants from other sources.

Prompt for AI agents
In `src/poetry/installation/installer.py` at line 239:

**Same-name packages update unexpectedly**

When the lock file has directory and non-directory variants with the same normalized package name, and the non-directory variant has a newer resolvable version, `Provider.get_locked()` skips locked packages by normalized name, so adding a directory package’s name to `use_latest` also bypasses a locked variant of that name from another source; the resolver selects a new variant and an unrelated package changes during the update.

Make the directory re-solve exemption source-specific so it does not bypass locked variants from other sources.

This branch has not been deployed

No deployments
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.

Transitive dependencies of path dependencies are not updated with poetry update X

1 participant