[rset] close #1683703: rset.get_entity crash on rql query with subquery and aggregat
--- a/rset.py Thu May 19 09:40:44 2011 +0200
+++ b/rset.py Thu May 19 09:43:23 2011 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
@@ -79,7 +79,7 @@
rows = rows[:10] + ['...']
if len(rows) > 1:
# add a line break before first entity if more that one.
- pattern = '<resultset %r (%s rows):\n%s>'
+ pattern = '<resultset %r (%s rows):\n%s>'
else:
pattern = '<resultset %r (%s rows): %s>'
@@ -673,8 +673,12 @@
root = rootselect.parent
selectmain = select.selection[selectidx]
for i, term in enumerate(rootselect.selection):
- rootvar = _get_variable(term)
- if rootvar is None:
+ try:
+ # don't use _get_variable here: if the term isn't a variable
+ # (function...), we don't want it to be used as an entity attribute
+ # or relation's value (XXX beside MAX/MIN trick?)
+ rootvar = term.variable
+ except AttributeError:
continue
if rootvar.name == rootmainvar.name:
continue
--- a/test/unittest_rset.py Thu May 19 09:40:44 2011 +0200
+++ b/test/unittest_rset.py Thu May 19 09:43:23 2011 +0200
@@ -1,5 +1,5 @@
# coding: utf-8
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
@@ -63,6 +63,13 @@
result = list(attr_desc_iterator(parse(rql).children[0], idx, idx))
self.assertEqual(result, relations)
+ def test_subquery_callfunc(self):
+ rql = ('Any A,B,C,COUNT(D) GROUPBY A,B,C WITH A,B,C,D BEING '
+ '(Any YEAR(CD), MONTH(CD), S, X WHERE X is CWUser, X creation_date CD, X in_state S)')
+ rqlst = parse(rql)
+ select, col = rqlst.locate_subquery(2, 'CWUser', None)
+ result = list(attr_desc_iterator(select, col, 2))
+ self.assertEqual(result, [])
class ResultSetTC(CubicWebTC):