sdispater / mixology

A generic dependency-resolution library written in pure Python

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Bug in version solver when using a hashable object to represent a package, not just a string.

Greedquest opened this issue · comments

I believe it's this line:

changed.add(str(self._propagate_incompatibility(root_cause)))

self._propagate_incompatibility will return the _conflict type which is the hashable type used to represent a package (in my usecase this is not a string). The line converts it to str which is a problem since then it is no longer a valid key in the self._incompatibilities dictionary (line 113 of the same function).

def _propagate(self, package): # type: (Hashable) -> None
"""
Performs unit propagation on incompatibilities transitively
related to package to derive new assignments for _solution.
"""
changed = set()
changed.add(package)
while changed:
package = changed.pop()
# Iterate in reverse because conflict resolution tends to produce more
# general incompatibilities as time goes on. If we look at those first,
# we can derive stronger assignments sooner and more eagerly find
# conflicts.
for incompatibility in reversed(self._incompatibilities[package]):
result = self._propagate_incompatibility(incompatibility)
if result is _conflict:
# If the incompatibility is satisfied by the solution, we use
# _resolve_conflict() to determine the root cause of the conflict as a
# new incompatibility.
#
# It also backjumps to a point in the solution
# where that incompatibility will allow us to derive new assignments
# that avoid the conflict.
root_cause = self._resolve_conflict(incompatibility)
# Back jumping erases all the assignments we did at the previous
# decision level, so we clear [changed] and refill it with the
# newly-propagated assignment.
changed.clear()
changed.add(str(self._propagate_incompatibility(root_cause)))
break
elif result is not None:
changed.add(result)