[rql annotation] fix has_text_query detection (if coming from sub-query and if has_text on a column aliases. Closes #2275322
--- a/server/querier.py Thu Apr 05 14:44:00 2012 +0200
+++ b/server/querier.py Mon Mar 26 12:11:48 2012 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
@@ -723,7 +723,7 @@
rqlst = rqlst.copy()
self._annotate(rqlst)
if args:
- # different SQL generated when some argument is None or not (IS
+ # different SQL generated when some argument is None or not (IS
# NULL). This should be considered when computing sql cache key
cachekey += tuple(sorted([k for k,v in args.iteritems()
if v is None]))
--- a/server/rqlannotation.py Thu Apr 05 14:44:00 2012 +0200
+++ b/server/rqlannotation.py Mon Mar 26 12:11:48 2012 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
@@ -28,12 +28,13 @@
from rql.utils import common_parent
def _annotate_select(annotator, rqlst):
+ has_text_query = False
for subquery in rqlst.with_:
- annotator._annotate_union(subquery.query)
+ if annotator._annotate_union(subquery.query):
+ has_text_query = True
#if server.DEBUG:
# print '-------- sql annotate', repr(rqlst)
getrschema = annotator.schema.rschema
- has_text_query = False
need_distinct = rqlst.distinct
for rel in rqlst.iget_nodes(Relation):
if getrschema(rel.r_type).symmetric and not isinstance(rel.parent, Exists):
@@ -154,6 +155,11 @@
sstinfo['scope'] = common_parent(sstinfo['scope'], stinfo['scope']).scope
except CantSelectPrincipal:
stinfo['invariant'] = False
+ # see unittest_rqlannotation. test_has_text_security_cache_bug
+ # XXX probably more to do, but yet that work without more...
+ for col_alias in rqlst.aliases.itervalues():
+ if col_alias.stinfo.get('ftirels'):
+ has_text_query = True
rqlst.need_distinct = need_distinct
return has_text_query
@@ -272,8 +278,7 @@
def _annotate_union(self, union):
has_text_query = False
for select in union.children:
- htq = _annotate_select(self, select)
- if htq:
+ if _annotate_select(self, select):
has_text_query = True
return has_text_query
--- a/server/test/unittest_querier.py Thu Apr 05 14:44:00 2012 +0200
+++ b/server/test/unittest_querier.py Mon Mar 26 12:11:48 2012 +0200
@@ -1,5 +1,5 @@
# -*- coding: iso-8859-1 -*-
-# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
@@ -28,7 +28,7 @@
from cubicweb.server.utils import crypt_password
from cubicweb.server.sources.native import make_schema
from cubicweb.devtools import get_test_db_handler, TestServerConfiguration
-
+from cubicweb.devtools.testlib import CubicWebTC
from cubicweb.devtools.repotest import tuplify, BaseQuerierTC
from unittest_session import Variable
@@ -1501,5 +1501,17 @@
self.assertFalse(self.execute('Any X WHERE X is CWEType, X name %(name)s', {'name': None}))
self.assertTrue(self.execute('Any X WHERE X is CWEType, X name %(name)s', {'name': 'CWEType'}))
+class NonRegressionTC(CubicWebTC):
+ def test_has_text_security_cache_bug(self):
+ self.create_user('user', ('users',))
+ req = self.request()
+ aff1 = req.create_entity('Societe', nom=u'aff1')
+ aff2 = req.create_entity('Societe', nom=u'aff2')
+ self.commit()
+ with self.login('user', password='user'):
+ res = self.execute('Any X WHERE X has_text %(text)s', {'text': 'aff1'})
+ self.assertEqual(res.rows, [[aff1.eid]])
+ res = self.execute('Any X WHERE X has_text %(text)s', {'text': 'aff2'})
+ self.assertEqual(res.rows, [[aff2.eid]])
if __name__ == '__main__':
unittest_main()
--- a/server/test/unittest_rqlannotation.py Thu Apr 05 14:44:00 2012 +0200
+++ b/server/test/unittest_rqlannotation.py Mon Mar 26 12:11:48 2012 +0200
@@ -1,5 +1,5 @@
# -*- coding: iso-8859-1 -*-
-# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.
@@ -350,6 +350,12 @@
self.assertEqual(rqlst.defined_vars['X']._q_invariant, False)
self.assertEqual(rqlst.defined_vars['Y']._q_invariant, True)
+
+ def test_has_text_security_cache_bug(self):
+ rqlst = self._prepare('Any X WHERE X has_text "toto" WITH X BEING '
+ '(Any C WHERE C is Societe, C nom CS)')
+ self.assertTrue(rqlst.parent.has_text_query)
+
if __name__ == '__main__':
from logilab.common.testlib import unittest_main
unittest_main()
--- a/test/unittest_rqlrewrite.py Thu Apr 05 14:44:00 2012 +0200
+++ b/test/unittest_rqlrewrite.py Mon Mar 26 12:11:48 2012 +0200
@@ -1,4 +1,4 @@
-# copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
#
# This file is part of CubicWeb.