Skip to content

fix(solver): prune sibling deps disjoint with override marker context#10944

Open
dimbleby wants to merge 1 commit into
python-poetry:mainfrom
dimbleby:fix-5506
Open

fix(solver): prune sibling deps disjoint with override marker context#10944
dimbleby wants to merge 1 commit into
python-poetry:mainfrom
dimbleby:fix-5506

Conversation

@dimbleby

@dimbleby dimbleby commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Another one that looks plausible, has a convincing testcase, is probably right...


When the solver retries under an override branch for a duplicate dependency, sibling dependencies whose markers are disjoint with the override's effective marker context were still considered. Their transitive constraints then spuriously conflicted with the overridden constraint, causing resolution to fail even when a valid solution existed (e.g. a transitive dep pinning a different version of the overridden package on a marker branch that does not apply).

Extend the existing overrides_marker_intersection mechanism into complete_package so such siblings are pruned during the solve phase, mirroring the filter already applied to duplicate deps.

Fixes #5506.

When the solver retries under an override branch for a duplicate
dependency, sibling dependencies whose markers are disjoint with the
override's effective marker context were still considered. Their
transitive constraints then spuriously conflicted with the overridden
constraint, causing resolution to fail even when a valid solution
existed (e.g. a transitive dep pinning a different version of the
overridden package on a marker branch that does not apply).

Extend the existing overrides_marker_intersection mechanism into
complete_package so such siblings are pruned during the solve phase,
mirroring the filter already applied to duplicate deps.

Fixes python-poetry#5506.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@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 left some high level feedback:

  • In complete_package, the new marker-pruning logic relies on self._overrides_marker_intersection always being a meaningful context; consider either explicitly guarding this with an "in override" condition or asserting/documenting what the default intersection represents when not in an override branch so future changes don't break this assumption.
  • The comment above the new if self._overrides_marker_intersection.intersect(dep.marker).is_empty(): check describes behavior "when solving under an override" but the code runs unconditionally; aligning the implementation with the comment (or clarifying the comment) would make the control flow and intent easier to follow.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `complete_package`, the new marker-pruning logic relies on `self._overrides_marker_intersection` always being a meaningful context; consider either explicitly guarding this with an "in override" condition or asserting/documenting what the default intersection represents when not in an override branch so future changes don't break this assumption.
- The comment above the new `if self._overrides_marker_intersection.intersect(dep.marker).is_empty():` check describes behavior "when solving under an override" but the code runs unconditionally; aligning the implementation with the comment (or clarifying the comment) would make the control flow and intent easier to follow.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

Solver breaks with related dependencies that are both conditional

1 participant