Skip to content

Comments

fix calculated markers if a dependency is required by several groups with different markers#10613

Merged
radoering merged 1 commit intopython-poetry:mainfrom
radoering:fix-group-dependent-marker
Nov 15, 2025
Merged

fix calculated markers if a dependency is required by several groups with different markers#10613
radoering merged 1 commit intopython-poetry:mainfrom
radoering:fix-group-dependent-marker

Conversation

@radoering
Copy link
Member

@radoering radoering commented Nov 7, 2025

This also fixes the case where a dependency is required in an extra and a group.

Pull Request Check List

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

Summary by Sourcery

Improve marker calculation to correctly handle dependencies required by multiple groups or extras by grouping edge-specific markers and updating both DFS and transitive marker aggregation

Bug Fixes:

  • Fix incorrect marker propagation for dependencies shared across different groups or extras

Enhancements:

  • Refactor internal marker storage to key edge markers by the set of dependency groups

Tests:

  • Add tests for propagating markers when a dependency appears in multiple groups and in extras

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 7, 2025

Reviewer's Guide

Enhance marker propagation to handle dependencies required by multiple groups or extras by tracking markers per group set and merging them in depth-first traversal and calculation phases, with accompanying tests.

Class diagram for updated marker tracking in dependency graph

classDiagram
    class Solver {
    }
    class PackageNode {
        +package: Package
        +groups: frozenset[NormalizedName]
        +marker: BaseMarker
        +reachable(): list[PackageNode]
    }
    class Package {
    }
    class BaseMarker {
        +union(other: BaseMarker): BaseMarker
        +intersect(other: BaseMarker): BaseMarker
        +without_extras(): BaseMarker
    }
    class EmptyMarker {
    }
    class MarkerOriginDict {
        <<defaultdict>>
        +[child_package][parent_package][groups]: BaseMarker
    }
    Solver --> MarkerOriginDict
    PackageNode --> Package
    PackageNode --> BaseMarker
    BaseMarker <|-- EmptyMarker
    MarkerOriginDict o-- Package
    MarkerOriginDict o-- BaseMarker
Loading

Flow diagram for marker propagation in depth-first search and calculation

flowchart TD
    A["Start DFS traversal"] --> B["For each out_neighbor in node.reachable()"]
    B --> C["Get groups for out_neighbor"]
    C --> D["Retrieve previous marker for (child, parent, groups)"]
    D --> E["Compute new marker (with or without extras)"]
    E --> F["Update markers[child][parent][groups] with union"]
    F --> G["Continue DFS visit"]
    G --> H["Insert node in sorted list"]

    H --> I["Calculate markers phase"]
    I --> J["For each package, for each parent, for each group set"]
    J --> K["If parent has groups, merge/intersect per-group markers"]
    J --> L["If parent is root, add edge marker to corresponding child groups"]
    K --> M["Update transitive_marker for each group"]
    L --> M
    M --> N["Assign transitive_marker to package info"]
Loading

File-Level Changes

Change Details Files
Extend MarkerOriginDict to key markers by frozenset of groups
  • Updated type alias to nested default dict with frozenset keys
  • Modified markers initialization to return nested default dicts
  • Adjusted MarkerOriginDict instantiation in depth_first_search
src/poetry/puzzle/solver.py
Record and merge markers per group set in dfs_visit
  • Extract out_neighbor.groups as key
  • Retrieve and union prev_marker and new_marker per group set
  • Store updated markers in nested dict by group frozenset
src/poetry/puzzle/solver.py
Revise calculate_markers to iterate over per-group edge markers
  • Loop through group_markers dict for each parent
  • Intersect and union markers per child group when parent has groups
  • For root parents, assert non-empty groups and union only into matching child groups
src/poetry/puzzle/solver.py
Add tests for dependencies used in multiple groups or extras
  • Introduce test for same dependency in different groups with distinct markers
  • Add test for dependency appearing in a group and an extra
tests/puzzle/test_solver_internals.py

Possibly linked issues

  • #Poetry constraint validation does not seem to take account of markers: The PR fixes how Poetry calculates markers for dependencies with multiple groups/extras, directly addressing the issue's dependency resolution problem.
  • #issue: The PR fixes how Poetry calculates markers for dependencies in multiple groups or with extras, preventing incorrect constraint collapsing in the lockfile.
  • #issue: The PR fixes the issue by refining marker calculation for dependencies required by multiple groups or extras, resolving conflicts.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

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

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

## Individual Comments

### Comment 1
<location> `src/poetry/puzzle/solver.py:281-282` </location>
<code_context>
         back_edges[out_neighbor.id].append(node)
-        marker = markers[out_neighbor.package][node.package]
-        markers[out_neighbor.package][node.package] = marker.union(
+        groups = out_neighbor.groups
+        prev_marker = markers[out_neighbor.package][node.package][groups]
+        new_marker = (
             out_neighbor.marker
</code_context>

<issue_to_address>
**issue (bug_risk):** Using frozenset as a key for groups may lead to subtle bugs if group sets are not canonicalized.

Inconsistent construction of frozenset keys can cause missed updates or incorrect unions. Make sure group sets are always built in a consistent, canonical way before use.
</issue_to_address>

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.

…with different markers

This also fixes the case where a dependency is required in an extra and a group.
@radoering radoering force-pushed the fix-group-dependent-marker branch from c120bad to 9078783 Compare November 15, 2025 13:27
@radoering radoering merged commit 27253f2 into python-poetry:main Nov 15, 2025
63 checks passed
@github-actions
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 16, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant