[rqlrewrite] rewrite doesn't need a solutions argument, always use the Select'ones stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 24 Jul 2013 16:55:24 +0200
branchstable
changeset 9188 0677e03077fb
parent 9187 8406bef5d5f2
child 9189 9448215c73c4
[rqlrewrite] rewrite doesn't need a solutions argument, always use the Select'ones Also, do a copy systematically else it may lead to empty solutions depending on the rewrite path. Test case tentative included in the following changeset.
entity.py
rqlrewrite.py
test/unittest_rqlrewrite.py
--- a/entity.py	Wed Jul 24 16:49:40 2013 +0200
+++ b/entity.py	Wed Jul 24 16:55:24 2013 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -1181,8 +1181,7 @@
                               if v in select.defined_vars and v in cstr.mainvars)
                 # rewrite constraint by constraint since we want a AND between
                 # expressions.
-                rewriter.rewrite(select, [(varmap, (cstr,))], select.solutions,
-                                 args, existant)
+                rewriter.rewrite(select, [(varmap, (cstr,))], args, existant)
         # insert security RQL expressions granting the permission to 'add' the
         # relation into the rql syntax tree, if necessary
         rqlexprs = rdef.get_rqlexprs('add')
@@ -1194,8 +1193,7 @@
             varmap = dict((v, v) for v in (searchedvar.name, evar.name)
                           if v in select.defined_vars)
             # rewrite all expressions at once since we want a OR between them.
-            rewriter.rewrite(select, [(varmap, rqlexprs)], select.solutions,
-                             args, existant)
+            rewriter.rewrite(select, [(varmap, rqlexprs)], args, existant)
         # ensure we have an order defined
         if not select.orderby:
             select.add_sort_var(select.defined_vars[searchedvar.name])
--- a/rqlrewrite.py	Wed Jul 24 16:49:40 2013 +0200
+++ b/rqlrewrite.py	Wed Jul 24 16:55:24 2013 +0200
@@ -303,7 +303,7 @@
             myunion.append(myrqlst)
             # in-place rewrite + annotation / simplification
             lcheckdef = [({var: 'X'}, rqlexprs) for var, rqlexprs in lcheckdef]
-            self.rewrite(myrqlst, lcheckdef, lchecksolutions, kwargs)
+            self.rewrite(myrqlst, lcheckdef, kwargs)
             _add_noinvariant(noinvariant, restricted, myrqlst, nbtrees)
         if () in localchecks:
             select.set_possible_types(localchecks[()])
@@ -311,13 +311,14 @@
             _add_noinvariant(noinvariant, restricted, select, nbtrees)
         self.annotate(union)
 
-    def rewrite(self, select, snippets, solutions, kwargs, existingvars=None):
+    def rewrite(self, select, snippets, kwargs, existingvars=None):
         """
         snippets: (varmap, list of rql expression)
                   with varmap a *tuple* (select var, snippet var)
         """
         self.select = select
-        self.solutions = solutions
+        # remove_solutions used below require a copy
+        self.solutions = solutions = select.solutions[:]
         self.kwargs = kwargs
         self.u_varname = None
         self.removing_ambiguity = False
@@ -342,6 +343,7 @@
             select, solutions, newsolutions))
         if len(newsolutions) > len(solutions):
             newsolutions = self.remove_ambiguities(snippets, newsolutions)
+            assert newsolutions
         select.solutions = newsolutions
         add_types_restriction(self.schema, select)
 
@@ -611,7 +613,6 @@
                 exists = var.references()[0].scope
                 exists.add_constant_restriction(var, 'is', etype, 'etype')
         # recompute solutions
-        #select.annotated = False # avoid assertion error
         self.compute_solutions()
         # clean solutions according to initial solutions
         return remove_solutions(self.solutions, self.select.solutions,
--- a/test/unittest_rqlrewrite.py	Wed Jul 24 16:49:40 2013 +0200
+++ b/test/unittest_rqlrewrite.py	Wed Jul 24 16:55:24 2013 +0200
@@ -73,9 +73,7 @@
                     for snippet in exprs]
         snippets.append((dict([v]), rqlexprs))
     rqlhelper.compute_solutions(rqlst.children[0], {'eid': eid_func_map}, kwargs=kwargs)
-    solutions = rqlst.children[0].solutions
-    rewriter.rewrite(rqlst.children[0], snippets, solutions, kwargs,
-                     existingvars)
+    rewriter.rewrite(rqlst.children[0], snippets, kwargs, existingvars)
     test_vrefs(rqlst.children[0])
     return rewriter.rewritten