Fix: GenericEnv.is_venv() in src/poetry/utils/env/generic_env.py compared... - #11011
Open
M001N wants to merge 1 commit into
Open
Fix: GenericEnv.is_venv() in src/poetry/utils/env/generic_env.py compared...#11011M001N wants to merge 1 commit into
M001N wants to merge 1 commit into
Conversation
A version manager (e.g. mise) may expose the same interpreter through two different filesystem paths -- an unversioned symlink and the concrete fully-versioned install dir it points to. is_venv() compared self._path and self._base without normalizing such aliases, so it could incorrectly report True and cause create_venv() to skip creating a project-specific virtualenv. Fixes python-poetry#10991
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- Using
Path.resolve()on everyis_venv()call introduces filesystem access and potential exceptions if either path is missing; consider pre-normalizing/caching resolved paths at construction time or handling resolution failures explicitly. - The new test reaches into
env._pathandenv._basedirectly, which couples it to internals; if possible, construct theGenericEnvin a way that reflects realistic initialization while still exercising the aliasing behavior, to avoid future brittleness when internals change.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Using `Path.resolve()` on every `is_venv()` call introduces filesystem access and potential exceptions if either path is missing; consider pre-normalizing/caching resolved paths at construction time or handling resolution failures explicitly.
- The new test reaches into `env._path` and `env._base` directly, which couples it to internals; if possible, construct the `GenericEnv` in a way that reflects realistic initialization while still exercising the aliasing behavior, to avoid future brittleness when internals change.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changed is_venv() to resolve both paths before comparing:
return self._path.resolve() != self._base.resolve().Problem
python-poetry/poetry issue reference: #10991
Root Cause
GenericEnv.is_venv() in src/poetry/utils/env/generic_env.py compared self._path and self._base with plain inequality (
self._path != self._base) without resolving symlinks/aliases. When a Python version manager exposes the same interpreter via two different filesystem paths (e.g. an unversioned symlink and the concrete versioned directory it points to), the unresolved paths differ even though they refer to the same interpreter, so is_venv() incorrectly returns True. This causes EnvManager.create_venv() to believe Poetry is already running inside an isolated virtualenv and skip creating a project-specific venv.Testing
PASS - 35 passed, 1 skipped (pre-existing nix-only symlink test skipped on Windows); new test also independently verified to fail on unmodified code and pass with the fix.
Related Issue
#10991