# HG changeset patch # User Sylvain Thénault # Date 1305029234 -7200 # Node ID ed66f236715d8269f2ca1a684cbdfb48539e24f6 # Parent c6d8c3ce4a3ec2c82f140328bfe3c6860dccb18d fix _set_relation when no target eids, update datafeed source pull_data arguments to raise on error during tests diff -r c6d8c3ce4a3e -r ed66f236715d server/sources/datafeed.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 diff -r c6d8c3ce4a3e -r ed66f236715d sobjects/parsers.py --- 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__) diff -r c6d8c3ce4a3e -r ed66f236715d sobjects/test/unittest_parsers.py --- 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)