Fix dependency cache inconsistency with prerelease versions #7978
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.
This PR fixes an inconsistency identified in #7950 (comment) where in some situations Poetry will not select a prerelease package version even though it satisfies all constraints.
Poetry is supposed to consider prerelease package versions if no other package versions satisfy the constraints. I believe this works if the constrained dependency is at the top level, but not necessarily if the constraint is introduced at a later level. Currently, whether it works or not depends on some arbitrary factors like the order dependencies are evaluated in and if the solver recently backtracked.
Regression test
I introduced a regression test which fails on
master
:The test passes if I disable the
DependencyCache
(replace the contents ofDependencyCache._search_for()
withreturn self.provider.search_for(dependency)
, and also passes with the patch provided in this PR.Additionally, the reproduction using
black<22
from #7950 (comment) also succeeds for me now.