Repository navigation
fix(solver): apply active extras before splitting Python markers - #11301
notatallshaw wants to merge 2 commits into
Conversation
Linked issuesChecked at commit a2ac6c0 #11262 poetry lock >= 2.5.0: overlapping markers for a package locked in two versions (torch / nvidia-cuda-nvrtc) · 1 of 1 met
#11300 `poetry lock` stalls with sktime's `dl` and `notebooks` extras · 1 of 1 met
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="src/poetry/puzzle/provider.py" line_range="97" />
<code_context>
+ dependencies = []
+ for dep in package.extras.get(name, ()):
+ if dep.name == package.name:
+ pending.extend(sorted(dep.extras))
+ else:
+ dependencies.append(dep)
</code_context>
<issue_to_address>
**Conditional extras widen override regions**
When a selected extra references another extra on the same package under a Python or platform marker, `_iter_package_extras` queues the referenced extras without retaining the self-reference marker, and `get_override_marker` treats every yielded extra as active across the whole override. Override results therefore include environments where the nested extra is not enabled, so the merged package markers can be wrong.
Carry the self-reference marker through extra expansion and restrict each nested extra’s contribution to the environments where that marker applies.
Also at `src/poetry/puzzle/provider.py:116`.
</issue_to_address>
### Comment 2
<location path="tests/puzzle/test_solver.py" line_range="5868" />
<code_context>
+ ">=3.6,<3.13",
+ ["dask"],
+ {"3.6": "2021.12.0", "3.7": "2021.12.0", "3.12": "2021.3.0"},
+ ),
+ ],
+)
</code_context>
<issue_to_address>
**Missing lower bound goes unnoticed**
When the impossible-conflict case drops the applicable `leaf>=2` requirement, the solver drops the always-applicable `leaf>=2` requirement in the `impossible-conflict` case, and the root’s unconstrained `leaf` dependency still selects 2.0. `test_solver_limits_override_markers_to_the_owners_extras` therefore passes its 2.0 assertion without showing that this requirement was applied.
Add an assertion that distinguishes enforcing `leaf>=2` from resolving the root’s wildcard dependency alone.
</issue_to_address>Sourcery assessment
Needs a human reviewer. 2 findings to address first, and if the marker branches are combined incorrectly, the solver can select or record the wrong dependency version for some Python or extra combinations. Reverting restores the old solver behavior, but lockfiles already generated with the wrong resolution would need to be regenerated; that state is bounded and repairable.
Blocking findings: src/poetry/puzzle/provider.py:97, tests/puzzle/test_solver.py:5868
97baf5b to
42c0c1e
Compare
|
Thanks - continuing to trust my AI on such matters - it agrees that this fixes cases that #11264 does not, but proposes that there are parts from the earlier PR worth keeping. Any chance you can include them here?
|
I replaced this PR’s extra iterator with a private helper that returns a mapping from extra names to dependencies, both callers use it, simplifying bookkeeping. I brought over #11264’s regression for #11262 and its test for extras with the same name. I added a check for the lib version because #11264’s check for essential still passed when I deliberately mixed the packages’ extras. I kept the platform test since it already checks x86_64, aarch64, and the uncovered case on s390x. |
Resolves: #11300
Resolves: #11262
Alternative to: #11264 (which fixes #11262 but not #11300)
This PR checks the selected extras before deciding which dependency rules apply to the project’s Python range. In #11300, sktime’s dl extra requires
pytorch-forecastingversion 1.8.0 or newer throughout Python 3.12, so the fallback that allows any version never applies.Compared to #11264, which fixes how Poetry combines results in the lockfile, this PR also skips that fallback before starting a separate solve.