From c956cdd79a3a41b0675cd410945ca6556a9900d9 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Thu, 5 Apr 2012 17:48:11 +0100 Subject: [PATCH] Fixed error solving with optional dependencies If the dependency contained no implementations and we needed to choose the next variable to try, the result was: File ".../zeroinstall/injector/solver.py", line 571, in find_undecided group = group_clause_for[uri] KeyError: u'...' This could easily happen if the feed for the dependency wasn't cached yet. Reported by Tim Cuthbertson. --- tests/OptionalMissing.xml | 14 ++++++++++++++ tests/testsolver.py | 5 +++++ zeroinstall/injector/solver.py | 8 +++++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/OptionalMissing.xml diff --git a/tests/OptionalMissing.xml b/tests/OptionalMissing.xml new file mode 100644 index 0000000..dabd03f --- /dev/null +++ b/tests/OptionalMissing.xml @@ -0,0 +1,14 @@ + + + OptionalMissing + optional dependency on a missing interface + + + + + + + + + + diff --git a/tests/testsolver.py b/tests/testsolver.py index fec0a81..3552b3c 100755 --- a/tests/testsolver.py +++ b/tests/testsolver.py @@ -225,5 +225,10 @@ class TestSolver(BaseTest): watch_xml = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'watchdog.xml') s.solve(watch_xml, arch.get_architecture(None, None), command_name = 'test') + def testRecommendBug(self): + s = solver.DefaultSolver(self.config) + optional_missing_xml = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'OptionalMissing.xml') + s.solve(optional_missing_xml, arch.get_architecture(None, None), command_name = None) + if __name__ == '__main__': unittest.main() diff --git a/zeroinstall/injector/solver.py b/zeroinstall/injector/solver.py index 0d5c4c7..3cae3c3 100644 --- a/zeroinstall/injector/solver.py +++ b/zeroinstall/injector/solver.py @@ -568,7 +568,13 @@ class SATSolver(Solver): return # Break cycles seen.add(uri) - group = group_clause_for[uri] + group = group_clause_for.get(uri, None) + + if group is None: + # (can be None if the selected impl has an optional dependency on + # a feed with no implementations) + return + #print "Group for %s = %s" % (uri, group) lit = group.current if lit is None: -- 2.11.4.GIT