diff --git a/src/poetry/puzzle/provider.py b/src/poetry/puzzle/provider.py index 83fef2b30cd..474b1703b36 100644 --- a/src/poetry/puzzle/provider.py +++ b/src/poetry/puzzle/provider.py @@ -638,8 +638,9 @@ def fmt_warning(d: Dependency) -> str: dep_other.set_constraint( dep_other.constraint.intersect(dep_any.constraint) ) - else: - # if there is no any marker dependency, + elif not inverted_marker.is_empty(): + # if there is no any marker dependency + # and the inverted marker is not empty, # a dependency with the inverted union of all markers is required # in order to not miss other dependencies later, for instance: # - foo (1.0) ; python == 3.7 @@ -655,10 +656,11 @@ def fmt_warning(d: Dependency) -> str: overrides = [] overrides_marker_intersection = AnyMarker() - for _dep in self._overrides.get(package, {}).values(): - overrides_marker_intersection = overrides_marker_intersection.intersect( - _dep.marker - ) + for dep_overrides in self._overrides.values(): + for _dep in dep_overrides.values(): + overrides_marker_intersection = ( + overrides_marker_intersection.intersect(_dep.marker) + ) for _dep in _deps: if not overrides_marker_intersection.intersect(_dep.marker).is_empty(): current_overrides = self._overrides.copy() diff --git a/tests/puzzle/test_solver.py b/tests/puzzle/test_solver.py index a9e8d0d7674..5f76e5d3f9d 100644 --- a/tests/puzzle/test_solver.py +++ b/tests/puzzle/test_solver.py @@ -1414,6 +1414,49 @@ def test_solver_duplicate_dependencies_ignore_overrides_with_empty_marker_inters ) +def test_solver_duplicate_dependencies_ignore_overrides_with_empty_marker_intersection2( + solver: Solver, repo: Repository, package: Package +): + """ + Empty intersection between top level dependency and transient dependency. + """ + package.add_dependency(Factory.create_dependency("A", {"version": "1.0"})) + package.add_dependency( + Factory.create_dependency("B", {"version": ">=2.0", "python": ">=3.7"}) + ) + package.add_dependency( + Factory.create_dependency("B", {"version": "*", "python": "<3.7"}) + ) + + package_a10 = get_package("A", "1.0") + package_a10.add_dependency( + Factory.create_dependency("B", {"version": ">=2.0", "python": ">=3.7"}) + ) + package_a10.add_dependency( + Factory.create_dependency("B", {"version": "*", "python": "<3.7"}) + ) + + package_b10 = get_package("B", "1.0") + package_b10.python_versions = "<3.7" + package_b20 = get_package("B", "2.0") + package_b20.python_versions = ">=3.7" + + repo.add_package(package_a10) + repo.add_package(package_b10) + repo.add_package(package_b20) + + transaction = solver.solve() + + check_solver_result( + transaction, + [ + {"job": "install", "package": package_b10}, + {"job": "install", "package": package_b20}, + {"job": "install", "package": package_a10}, + ], + ) + + def test_solver_duplicate_dependencies_sub_dependencies( solver: Solver, repo: Repository, package: ProjectPackage ):