one more msplanning bug fixed... tls-sprint
authorsylvain.thenault@logilab.fr
Wed, 13 May 2009 16:28:21 +0200
branchtls-sprint
changeset 1786 eccd1885d42e
parent 1785 01245e2a777d
child 1787 71c143c0ada3
one more msplanning bug fixed...
server/msplanner.py
server/test/unittest_msplanner.py
server/test/unittest_multisources.py
--- a/server/msplanner.py	Wed May 13 15:46:47 2009 +0200
+++ b/server/msplanner.py	Wed May 13 16:28:21 2009 +0200
@@ -260,8 +260,13 @@
             self._insert_identity_variable = rqlhelper._annotator.rewrite_shared_optional
         if server.DEBUG:
             print 'sourcesterms:'
-            for source, terms in self.sourcesterms.items():
-                print source, terms
+            self._debug_sourcesterms()
+
+    def _debug_sourcesterms(self):
+        for source in self._sourcesterms:
+            print '-', source
+            for term, sols in self._sourcesterms[source].items():
+                print '  -', term, id(term), ':' ,sols
 
     def copy_solutions(self, solindices):
         return [self._solutions[solidx].copy() for solidx in solindices]
@@ -358,7 +363,8 @@
                         # doesn't actually comes from it so we get a changes
                         # that allequals will return True as expected when
                         # computing needsplit
-                        if self.system_source in sourcesterms:
+                        # check const is used in a relation restriction
+                        if const.relation() and self.system_source in sourcesterms:
                             self._set_source_for_term(self.system_source, const)
         # add source for relations
         rschema = self._schema.rschema
@@ -605,6 +611,8 @@
             try:
                 sourcesterms[source][term].remove(solindex)
             except KeyError:
+                import rql.base as rqlb
+                assert isinstance(term, rqlb.BaseNode), repr(term)
                 continue # may occur with subquery column alias
             if not sourcesterms[source][term]:
                 del sourcesterms[source][term]
--- a/server/test/unittest_msplanner.py	Wed May 13 15:46:47 2009 +0200
+++ b/server/test/unittest_msplanner.py	Wed May 13 16:28:21 2009 +0200
@@ -2090,13 +2090,21 @@
                      )]
                    )
 
-    def test_nonregr_dont_cross_rel_source_filtering(self):
+    def test_nonregr_dont_cross_rel_source_filtering_1(self):
+        self.repo._type_source_cache[999999] = ('Note', 'cards', 999999)
+        self._test('Any S WHERE E eid %(x)s, E in_state S, NOT S name "moved"',
+                   [('OneFetchStep', [('Any S WHERE 999999 in_state S, NOT S name "moved", S is State',
+                                       [{'S': 'State'}])],
+                     None, None, [self.rql], {}, []
+                     )],
+                   {'x': 999999})
+
+    def test_nonregr_dont_cross_rel_source_filtering_2(self):
         self.repo._type_source_cache[999999] = ('Note', 'cards', 999999)
         self._test('Any X,AA,AB WHERE E eid %(x)s, E in_state X, X name AA, X modification_date AB',
                    [('OneFetchStep', [('Any X,AA,AB WHERE 999999 in_state X, X name AA, X modification_date AB, X is State',
                                        [{'AA': 'String', 'AB': 'Datetime', 'X': 'State'}])],
-                     None, None,
-                     [self.rql], {}, []
+                     None, None, [self.rql], {}, []
                      )],
                    {'x': 999999})
 
--- a/server/test/unittest_multisources.py	Wed May 13 15:46:47 2009 +0200
+++ b/server/test/unittest_multisources.py	Wed May 13 16:28:21 2009 +0200
@@ -10,10 +10,10 @@
 class TwoSourcesConfiguration(TestServerConfiguration):
     sourcefile = 'sources_multi'
 
-        
+
 class ExternalSource1Configuration(TestServerConfiguration):
     sourcefile = 'sources_extern'
-        
+
 class ExternalSource2Configuration(TestServerConfiguration):
     sourcefile = 'sources_multi2'
 
@@ -41,6 +41,8 @@
 
     def setUp(self):
         RepositoryBasedTC.setUp(self)
+        self.repo.sources[-1]._query_cache.clear()
+        self.repo.sources[-2]._query_cache.clear()
         # trigger discovery
         self.execute('Card X')
         self.execute('Affaire X')
@@ -53,7 +55,7 @@
         self.ic2 = self.execute('INSERT Card X: X title "C2: Ze internal card", X wikiid "zzzi"')[0][0]
         self.commit()
         do_monkey_patch()
-        
+
     def tearDown(self):
         RepositoryBasedTC.tearDown(self)
         undo_monkey_patch()
@@ -63,15 +65,15 @@
         self.assertEquals(len(rset), 4)
         rset = self.execute('Any X,T WHERE X title T, X eid > 1')
         self.assertEquals(len(rset), 4)
-        
+
     def test_metainformation(self):
         rset = self.execute('Card X ORDERBY T WHERE X title T')
         # 2 added to the system source, 2 added to the external source
         self.assertEquals(len(rset), 4)
         # since they are orderd by eid, we know the 3 first one is coming from the system source
         # and the others from external source
-        self.assertEquals(rset.get_entity(0, 0).metainformation(), 
-                          {'source': {'adapter': 'native', 'uri': 'system'}, 
+        self.assertEquals(rset.get_entity(0, 0).metainformation(),
+                          {'source': {'adapter': 'native', 'uri': 'system'},
                            'type': u'Card', 'extid': None})
         externent = rset.get_entity(3, 0)
         metainf = externent.metainformation()
@@ -81,7 +83,7 @@
         etype = self.execute('Any ETN WHERE X is ET, ET name ETN, X eid %(x)s',
                              {'x': externent.eid}, 'x')[0][0]
         self.assertEquals(etype, 'Card')
-        
+
     def test_order_limit_offset(self):
         rsetbase = self.execute('Any W,X ORDERBY W,X WHERE X wikiid W')
         self.assertEquals(len(rsetbase), 4)
@@ -108,6 +110,7 @@
 
     def test_synchronization(self):
         cu = cnx2.cursor()
+        assert cu.execute('Any X WHERE X eid %(x)s', {'x': aff1}, 'x')
         cu.execute('SET X ref "BLAH" WHERE X eid %(x)s', {'x': aff1}, 'x')
         aff2 = cu.execute('INSERT Affaire X: X ref "AFFREUX", X in_state S WHERE S name "pitetre"')[0][0]
         cnx2.commit()
@@ -141,7 +144,7 @@
 
     def test_sort_func(self):
         self.execute('Affaire X ORDERBY DUMB_SORT(RF) WHERE X ref RF')
-        
+
     def test_sort_func_ambigous(self):
         self.execute('Any X ORDERBY DUMB_SORT(RF) WHERE X title RF')
 
@@ -150,7 +153,7 @@
                                    'Card', self.session)
         rset = self.execute('Any X WHERE X eid IN (%s, %s)' % (iec1, self.ic1))
         self.assertEquals(sorted(r[0] for r in rset.rows), sorted([iec1, self.ic1]))
-        
+
     def test_greater_eid(self):
         rset = self.execute('Any X WHERE X eid > %s' % self.maxeid)
         self.assertEquals(len(rset.rows), 2) # self.ic1 and self.ic2
@@ -161,13 +164,13 @@
         self.assertEquals(len(rset.rows), 2)
         # trigger discovery using another query
         crset = self.execute('Card X WHERE X title "glup"')
-        self.assertEquals(len(crset.rows), 1) 
+        self.assertEquals(len(crset.rows), 1)
         rset = self.execute('Any X WHERE X eid > %s' % self.maxeid)
         self.assertEquals(len(rset.rows), 3)
         rset = self.execute('Any MAX(X)')
         self.assertEquals(len(rset.rows), 1)
         self.assertEquals(rset.rows[0][0], crset[0][0])
-        
+
     def test_attr_unification_1(self):
         n1 = self.execute('INSERT Note X: X type "AFFREF"')[0][0]
         n2 = self.execute('INSERT Note X: X type "AFFREU"')[0][0]
@@ -192,14 +195,14 @@
     def test_attr_unification_neq_2(self):
         # XXX complete
         self.execute('Any X,Y WHERE X is Card, Y is Affaire, X creation_date D, Y creation_date > D')
-        
+
     def test_union(self):
         afeids = self.execute('Affaire X')
         ueids = self.execute('CWUser X')
         rset = self.execute('(Any X WHERE X is Affaire) UNION (Any X WHERE X is CWUser)')
         self.assertEquals(sorted(r[0] for r in rset.rows),
                           sorted(r[0] for r in afeids + ueids))
-        
+
     def test_subquery1(self):
         rsetbase = self.execute('Any W,X WITH W,X BEING (Any W,X ORDERBY W,X WHERE X wikiid W)')
         self.assertEquals(len(rsetbase), 4)
@@ -210,11 +213,11 @@
         self.assertEquals(rset.rows, rsetbase.rows[2:4])
         rset = self.execute('Any W,X WITH W,X BEING (Any W,X ORDERBY W,X LIMIT 2 OFFSET 2 WHERE X wikiid W)')
         self.assertEquals(rset.rows, rsetbase.rows[2:4])
-        
+
     def test_subquery2(self):
         affeid = self.execute('Affaire X WHERE X ref "AFFREF"')[0][0]
-        rset =self.execute('Any X,AA,AB WITH X,AA,AB BEING (Any X,AA,AB WHERE E eid %(x)s, E in_state X, X name AA, X modification_date AB)',
-                           {'x': affeid})
+        rset = self.execute('Any X,AA,AB WITH X,AA,AB BEING (Any X,AA,AB WHERE E eid %(x)s, E in_state X, X name AA, X modification_date AB)',
+                            {'x': affeid})
         self.assertEquals(len(rset), 1)
         self.assertEquals(rset[0][1], "pitetre")
 
@@ -234,13 +237,13 @@
                                                        {'x': aff1}, 'x'))
         self.set_debug(False)
         self.assertSetEquals(notstates, states)
-        
+
     def test_nonregr1(self):
         ueid = self.session.user.eid
         affaire = self.execute('Affaire X WHERE X ref "AFFREF"').get_entity(0, 0)
         self.execute('Any U WHERE U in_group G, (G name IN ("managers", "logilab") OR (X require_permission P?, P name "bla", P require_group G)), X eid %(x)s, U eid %(u)s',
                      {'x': affaire.eid, 'u': ueid})
-        
+
     def test_nonregr2(self):
         treid = self.session.user.latest_trinfo().eid
         rset = self.execute('Any X ORDERBY D DESC WHERE E eid %(x)s, E wf_info_for X, X modification_date D',
@@ -251,7 +254,7 @@
 
     def test_nonregr3(self):
         self.execute('DELETE Card X WHERE X eid %(x)s, NOT X multisource_inlined_rel Y', {'x': self.ic1})
-        
+
 if __name__ == '__main__':
     from logilab.common.testlib import unittest_main
     unittest_main()