Merge with 3.26
authorDenis Laxalde <denis.laxalde@logilab.fr>
Tue, 19 Jun 2018 09:13:40 +0200
changeset 12327 58f05ffafeca
parent 12318 e947954e0ffc (current diff)
parent 12326 034bca253b55 (diff)
child 12328 b570d3094e32
Merge with 3.26
cubicweb/__pkginfo__.py
cubicweb/utils.py
requirements/test-web.txt
--- a/.hgtags	Fri Jun 15 17:45:26 2018 +0200
+++ b/.hgtags	Tue Jun 19 09:13:40 2018 +0200
@@ -625,3 +625,5 @@
 9bee3134d304f6cc51ab728b4ca84d464d1b3fd8 debian/3.26.2-1
 f7067be5f69cd05f34ce99fbb534e4674b3a782d 3.26.3
 f7067be5f69cd05f34ce99fbb534e4674b3a782d debian/3.26.3-1
+e1c1af68db86356e7893d7f808dcb76c87623b18 3.26.4
+e1c1af68db86356e7893d7f808dcb76c87623b18 debian/3.26.4-1
--- a/cubicweb.spec	Fri Jun 15 17:45:26 2018 +0200
+++ b/cubicweb.spec	Tue Jun 19 09:13:40 2018 +0200
@@ -8,7 +8,7 @@
 %{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
 
 Name:           cubicweb
-Version:        3.26.3
+Version:        3.26.4
 Release:        logilab.1%{?dist}
 Summary:        CubicWeb is a semantic web application framework
 Source0:        https://pypi.python.org/packages/source/c/cubicweb/cubicweb-%{version}.tar.gz
--- a/cubicweb/server/sources/rql2sql.py	Fri Jun 15 17:45:26 2018 +0200
+++ b/cubicweb/server/sources/rql2sql.py	Tue Jun 19 09:13:40 2018 +0200
@@ -279,6 +279,14 @@
                         groups.append(vref)
 
 
+def is_in_aggregat(node):
+    while node:
+        node = node.parent
+        if isinstance(node, Function) and node.descr().aggregat:
+            return True
+    return False
+
+
 def fix_selection_and_group(rqlst, needwrap, selectsortterms,
                             sorts, groups, having):
     if selectsortterms and sorts:
@@ -288,13 +296,11 @@
         # when a query is grouped, ensure sort terms are grouped as well
         for sortterm in sorts:
             term = sortterm.term
-            if not (isinstance(term, Constant) or
-                    (isinstance(term, Function) and
-                     get_func_descr(term.name).aggregat)):
-                for vref in term.iget_nodes(VariableRef):
-                    if not any(vref.is_equivalent(group) for group in groupvrefs):
-                        groups.append(vref)
-                        groupvrefs.append(vref)
+            for vref in term.iget_nodes(VariableRef):
+                if not (any(vref.is_equivalent(group) for group in groupvrefs)
+                        or is_in_aggregat(vref)):
+                    groups.append(vref)
+                    groupvrefs.append(vref)
     if needwrap and (groups or having):
         selectedidx = set(vref.name for term in rqlst.selection
                           for vref in term.get_nodes(VariableRef))
--- a/cubicweb/server/test/unittest_rql2sql.py	Fri Jun 15 17:45:26 2018 +0200
+++ b/cubicweb/server/test/unittest_rql2sql.py	Tue Jun 19 09:13:40 2018 +0200
@@ -1437,6 +1437,16 @@
 WHERE _X.cw_login ~ [0-9].*
 ''')
 
+    def test_aggregate_in_orderby(self):
+        self._check("Any X GROUPBY X ORDERBY ABS(COUNT(Y)) WHERE"
+                    "X is CWGROUP, Y is CWUSER, Y in_group X",
+                    '''SELECT rel_in_group1.eid_to
+FROM in_group_relation AS rel_in_group1, is_relation AS rel_is0, is_relation AS rel_is2
+WHERE rel_in_group1.eid_to=rel_is0.eid_from AND rel_in_group1.eid_from=rel_is2.eid_from
+GROUP BY rel_in_group1.eid_to
+ORDER BY ABS(COUNT(rel_in_group1.eid_from))
+''')
+
     def test_parser_parse(self):
         for rql, sql in PARSER:
             with self.subTest(rql=rql):
--- a/debian/changelog	Fri Jun 15 17:45:26 2018 +0200
+++ b/debian/changelog	Tue Jun 19 09:13:40 2018 +0200
@@ -1,3 +1,9 @@
+cubicweb (3.26.4-1) unstable; urgency=medium
+
+  * New upstream release.
+
+ -- Denis Laxalde <denis.laxalde@logilab.fr>  Mon, 18 Jun 2018 08:58:11 +0200
+
 cubicweb (3.26.3-1) unstable; urgency=medium
 
   * New upstream release.