diff --git a/src/poetry/mixology/version_solver.py b/src/poetry/mixology/version_solver.py index d0d59f4d6e3..841c4808244 100644 --- a/src/poetry/mixology/version_solver.py +++ b/src/poetry/mixology/version_solver.py @@ -368,11 +368,7 @@ def _get_min(dependency: Dependency) -> tuple[bool, int]: return not dependency.marker.is_any(), 1 locked = self._get_locked(dependency) - if locked and ( - dependency.constraint.allows(locked.version) - or locked.is_prerelease() - and dependency.constraint.allows(locked.version.next_patch()) - ): + if locked: return not dependency.marker.is_any(), 1 # VCS, URL, File or Directory dependencies @@ -399,7 +395,7 @@ def _get_min(dependency: Dependency) -> tuple[bool, int]: dependency = min(*unsatisfied, key=_get_min) locked = self._get_locked(dependency) - if locked is None or not dependency.constraint.allows(locked.version): + if locked is None: try: packages = self._dependency_cache.search_for(dependency) except ValueError as e: @@ -500,6 +496,13 @@ def _get_locked( if not allow_similar and not dependency.is_same_package_as(locked): return None + if not ( + dependency.constraint.allows(locked.version) + or locked.is_prerelease() + and dependency.constraint.allows(locked.version.next_patch()) + ): + return None + return locked def _log(self, text: str) -> None: