fix _set_relation when no target eids, update datafeed source pull_data arguments to raise on error during tests stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 10 May 2011 14:07:14 +0200
branchstable
changeset 7351 ed66f236715d
parent 7346 c6d8c3ce4a3e
child 7352 d68f9319bfda
child 7353 73d873681c7c
fix _set_relation when no target eids, update datafeed source pull_data arguments to raise on error during tests
server/sources/datafeed.py
sobjects/parsers.py
sobjects/test/unittest_parsers.py
--- a/server/sources/datafeed.py	Mon May 09 17:42:28 2011 +0200
+++ b/server/sources/datafeed.py	Tue May 10 14:07:14 2011 +0200
@@ -120,7 +120,7 @@
             return False
         return datetime.now() < (self.latest_retrieval + self.synchro_interval)
 
-    def pull_data(self, session, force=False):
+    def pull_data(self, session, force=False, raise_on_error=False):
         if not force and self.fresh():
             return {}
         if self.config['delete-entities']:
@@ -135,6 +135,8 @@
                 if parser.process(url):
                     error = True
             except IOError, exc:
+                if raise_on_error:
+                    raise
                 self.error('could not pull data while processing %s: %s',
                            url, exc)
                 error = True
--- a/sobjects/parsers.py	Mon May 09 17:42:28 2011 +0200
+++ b/sobjects/parsers.py	Tue May 10 14:07:14 2011 +0200
@@ -361,15 +361,18 @@
                              {'x': entity.eid})
 
     def _set_relation(self, entity, rtype, role, eids):
-        eidstr = ','.join(str(eid) for eid in eids)
-        rql = rtype_role_rql(rtype, role)
-        self._cw.execute('DELETE %s, NOT Y eid IN (%s)' % (rql, eidstr),
-                         {'x': entity.eid})
-        if role == 'object':
-            rql = 'SET %s, Y eid IN (%s), NOT Y %s X' % (rql, eidstr, rtype)
-        else:
-            rql = 'SET %s, Y eid IN (%s), NOT X %s Y' % (rql, eidstr, rtype)
+        rqlbase = rtype_role_rql(rtype, role)
+        rql = 'DELETE %s' % rqlbase
+        if eids:
+            eidstr = ','.join(str(eid) for eid in eids)
+            rql += ', NOT Y eid IN (%s)' % eidstr
         self._cw.execute(rql, {'x': entity.eid})
+        if eids:
+            if role == 'object':
+                rql = 'SET %s, Y eid IN (%s), NOT Y %s X' % (rqlbase, eidstr, rtype)
+            else:
+                rql = 'SET %s, Y eid IN (%s), NOT X %s Y' % (rqlbase, eidstr, rtype)
+            self._cw.execute(rql, {'x': entity.eid})
 
 def registration_callback(vreg):
     vreg.register_all(globals().values(), __name__)
--- a/sobjects/test/unittest_parsers.py	Mon May 09 17:42:28 2011 +0200
+++ b/sobjects/test/unittest_parsers.py	Tue May 10 14:07:14 2011 +0200
@@ -129,7 +129,7 @@
                              }
                           })
         session = self.repo.internal_session()
-        stats = dfsource.pull_data(session, force=True)
+        stats = dfsource.pull_data(session, force=True, raise_on_error=True)
         self.assertEqual(sorted(stats.keys()), ['created', 'updated'])
         self.assertEqual(len(stats['created']), 2)
         self.assertEqual(stats['updated'], set())
@@ -156,12 +156,12 @@
         self.assertEqual(tag.cwuri, 'http://testing.fr/cubicweb/%s' % tag.eid)
         self.assertEqual(tag.cw_source[0].name, 'system')
 
-        stats = dfsource.pull_data(session, force=True)
+        stats = dfsource.pull_data(session, force=True, raise_on_error=True)
         self.assertEqual(stats['created'], set())
         self.assertEqual(len(stats['updated']), 2)
         self.repo._type_source_cache.clear()
         self.repo._extid_cache.clear()
-        stats = dfsource.pull_data(session, force=True)
+        stats = dfsource.pull_data(session, force=True, raise_on_error=True)
         self.assertEqual(stats['created'], set())
         self.assertEqual(len(stats['updated']), 2)