[facets] should remove groupby from base rqlst. Closes #1796196 stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 01 Jul 2011 15:22:43 +0200
branchstable
changeset 7601 9030e8a4481e
parent 7598 781def950a85
child 7602 fbda46a4944f
[facets] should remove groupby from base rqlst. Closes #1796196 as we search for values for a variable, there seems to be no case where we would be interested in groups, though there are clearly some were leaving groups cause errors.
web/facet.py
web/test/unittest_facet.py
--- a/web/facet.py	Fri Jul 01 12:20:24 2011 +0200
+++ b/web/facet.py	Fri Jul 01 15:22:43 2011 +0200
@@ -78,7 +78,7 @@
 def prepare_facets_rqlst(rqlst, args=None):
     """prepare a syntax tree to generate facet filters
 
-    * remove ORDERBY clause
+    * remove ORDERBY/GROUPBY clauses
     * cleanup selection (remove everything)
     * undefine unnecessary variables
     * set DISTINCT
@@ -91,8 +91,10 @@
     select.set_limit(None)
     select.set_offset(None)
     baserql = select.as_string(kwargs=args)
-    # cleanup sort terms
+    # cleanup sort terms / group by
     select.remove_sort_terms()
+    select.remove_groups()
+    # XXX remove aggregat from having
     # selection: only vocabulary entity
     for term in select.selection[:]:
         select.remove_selected(term)
--- a/web/test/unittest_facet.py	Fri Jul 01 12:20:24 2011 +0200
+++ b/web/test/unittest_facet.py	Fri Jul 01 15:22:43 2011 +0200
@@ -66,18 +66,18 @@
         self.assertEqual(f.vocabulary(),
                           [(u'guests', guests), (u'managers', managers)])
         # ensure rqlst is left unmodified
-        self.assertEqual(rqlst.as_string(), 'DISTINCT Any  GROUPBY X WHERE X in_group G?, G name GN, NOT G name "users"')
+        self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X in_group G?, G name GN, NOT G name "users"')
         #rqlst = rset.syntax_tree()
         self.assertEqual(sorted(f.possible_values()),
                           [str(guests), str(managers)])
         # ensure rqlst is left unmodified
-        self.assertEqual(rqlst.as_string(), 'DISTINCT Any  GROUPBY X WHERE X in_group G?, G name GN, NOT G name "users"')
+        self.assertEqual(rqlst.as_string(), 'DISTINCT Any  WHERE X in_group G?, G name GN, NOT G name "users"')
         req.form[f.__regid__] = str(guests)
         f.add_rql_restrictions()
         # selection is cluttered because rqlst has been prepared for facet (it
         # is not in real life)
-        self.assertEqual(f.rqlst.as_string(),
-                          'DISTINCT Any  GROUPBY X WHERE X in_group G?, G name GN, NOT G name "users", X in_group D, D eid %s' % guests)
+        self.assertEqual(f.select.as_string(),
+                          'DISTINCT Any  WHERE X in_group G?, G name GN, NOT G name "users", X in_group D, D eid %s' % guests)
 
     def test_relation_no_relation_1(self):
         f, (guests, managers) = self._in_group_facet(no_relation=True)