[rewriter] fix latent bug: arbitrary etype may be substituted when using is_instance_of type restriction
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 12 Dec 2013 12:28:43 +0100
changeset 9358 1e0235478403
parent 9348 eacd02792332
child 9359 31a1813d53f3
[rewriter] fix latent bug: arbitrary etype may be substituted when using is_instance_of type restriction Note: the test is not deterministic because the bug depends on the iteration order on a set.
rqlrewrite.py
test/unittest_rqlrewrite.py
--- a/rqlrewrite.py	Wed Dec 11 12:22:52 2013 +0100
+++ b/rqlrewrite.py	Thu Dec 12 12:28:43 2013 +0100
@@ -92,6 +92,7 @@
                     for etype in possibletypes:
                         node.append(n.Constant(etype, 'etype'))
                 else:
+                    etype = iter(possibletypes).next()
                     node = n.Constant(etype, 'etype')
                 comp = mytyperel.children[1]
                 comp.replace(comp.children[0], node)
--- a/test/unittest_rqlrewrite.py	Wed Dec 11 12:22:52 2013 +0100
+++ b/test/unittest_rqlrewrite.py	Thu Dec 12 12:28:43 2013 +0100
@@ -486,6 +486,13 @@
         rqlst = parse('Any A, R WHERE A ref R, S is Affaire')
         rewrite(rqlst, {('A', 'X'): (c_ok, c_bad)}, {})
 
+    def test_nonregr_is_instance_of(self):
+        user_expr = ERQLExpression('NOT X in_group AF, AF name "guests"')
+        rqlst = parse('Any O WHERE S use_email O, S is CWUser, O is_instance_of EmailAddress')
+        rewrite(rqlst, {('S', 'X'): (user_expr,)}, {})
+        self.assertEqual(rqlst.as_string(),
+                         'Any O WHERE S use_email O, S is CWUser, O is EmailAddress, '
+                         'EXISTS(NOT S in_group A, A name "guests", A is CWGroup)')
 
 from cubicweb.devtools.testlib import CubicWebTC
 from logilab.common.decorators import classproperty