[rql2sql] fix relation table scope when some variable from subquery is used. Closes #3252270 stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 25 Oct 2013 12:23:06 +0200
branchstable
changeset 9324 a5ce068143ad
parent 9323 29d2f15cf596
child 9325 a4fc09836329
[rql2sql] fix relation table scope when some variable from subquery is used. Closes #3252270 While it feels weird to drop this explicit ColumnAlias handling, hg history has no clue on its introduction (prior to rev 0) and no older test case fails without it, so let's drop it.
server/sources/rql2sql.py
server/test/unittest_rql2sql.py
--- a/server/sources/rql2sql.py	Wed Oct 30 13:05:00 2013 +0100
+++ b/server/sources/rql2sql.py	Fri Oct 25 12:23:06 2013 +0200
@@ -486,13 +486,10 @@
             return relation._q_sqltable
         rid = 'rel_%s%s' % (relation.r_type, self.count)
         # relation's table is belonging to the root scope if it is the principal
-        # table of one of it's variable and if that variable belong's to parent
+        # table of one of its variable and that variable belong's to parent
         # scope
         for varref in relation.iget_nodes(VariableRef):
             var = varref.variable
-            if isinstance(var, ColumnAlias):
-                scope = 0
-                break
             # XXX may have a principal without being invariant for this generation,
             #     not sure this is a pb or not
             if var.stinfo.get('principal') is relation and var.scope is var.stmt:
--- a/server/test/unittest_rql2sql.py	Wed Oct 30 13:05:00 2013 +0100
+++ b/server/test/unittest_rql2sql.py	Fri Oct 25 12:23:06 2013 +0200
@@ -1478,6 +1478,20 @@
     def test_subquery(self):
         for t in self._parse((
 
+            ('Any X,N '
+             'WHERE NOT EXISTS(X owned_by U) '
+             'WITH X,N BEING '
+             '((Any X,N WHERE X name N, X is State)'
+             ' UNION '
+             '(Any XX,NN WHERE XX name NN, XX is Transition))',
+             '''SELECT _T0.C0, _T0.C1
+FROM ((SELECT _X.cw_eid AS C0, _X.cw_name AS C1
+FROM cw_State AS _X)
+UNION ALL
+(SELECT _XX.cw_eid AS C0, _XX.cw_name AS C1
+FROM cw_Transition AS _XX)) AS _T0
+WHERE NOT (EXISTS(SELECT 1 FROM owned_by_relation AS rel_owned_by0 WHERE rel_owned_by0.eid_from=_T0.C0))'''),
+
             ('Any N ORDERBY 1 WITH N BEING '
              '((Any N WHERE X name N, X is State)'
              ' UNION '
@@ -1551,7 +1565,8 @@
 GROUP BY _T.cw_eid) AS _T1 LEFT OUTER JOIN (SELECT _T.cw_eid AS C0, SUM(_T.cw_duration) AS C1
 FROM cw_Affaire AS _T LEFT OUTER JOIN tags_relation AS rel_tags0 ON (rel_tags0.eid_to=_T.cw_eid) LEFT OUTER JOIN cw_Tag AS _TAG ON (rel_tags0.eid_from=_TAG.cw_eid AND _TAG.cw_name=t)
 GROUP BY _T.cw_eid) AS _T0 ON (_T1.C0=_T0.C0)'''),
-            )):
+
+                             )):
             yield t