[datafeed / fti] rather control a 'complete' parameter than setting empty attribute values stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 26 Jul 2011 16:35:10 +0200
branchstable
changeset 7698 1c7411535c2d
parent 7697 ef50074a0314
child 7699 d07cde311630
[datafeed / fti] rather control a 'complete' parameter than setting empty attribute values
server/repository.py
server/sources/datafeed.py
sobjects/test/unittest_parsers.py
--- a/server/repository.py	Tue Jul 26 16:34:42 2011 +0200
+++ b/server/repository.py	Tue Jul 26 16:35:10 2011 +0200
@@ -1030,7 +1030,7 @@
         return extid
 
     def extid2eid(self, source, extid, etype, session=None, insert=True,
-                  sourceparams=None):
+                  complete=True, sourceparams=None):
         """Return eid from a local id. If the eid is a negative integer, that
         means the entity is known but has been copied back to the system source
         hence should be ignored.
@@ -1089,8 +1089,7 @@
                 session, extid, etype, eid, sourceparams)
             if source.should_call_hooks:
                 self.hm.call_hooks('before_add_entity', session, entity=entity)
-            # XXX call add_info with complete=False ?
-            self.add_info(session, entity, source, extid)
+            self.add_info(session, entity, source, extid, complete=complete)
             source.after_entity_insertion(session, extid, entity, sourceparams)
             if source.should_call_hooks:
                 self.hm.call_hooks('after_add_entity', session, entity=entity)
--- a/server/sources/datafeed.py	Tue Jul 26 16:34:42 2011 +0200
+++ b/server/sources/datafeed.py	Tue Jul 26 16:35:10 2011 +0200
@@ -220,9 +220,6 @@
         entity.cw_edited['cwuri'] = unicode(lid)
         entity.cw_edited.set_defaults()
         sourceparams['parser'].before_entity_copy(entity, sourceparams)
-        # avoid query to search full-text indexed attributes
-        for attr in entity.e_schema.indexable_attributes():
-            entity.cw_edited.setdefault(attr, u'')
         return entity
 
     def after_entity_insertion(self, session, lid, entity, sourceparams):
@@ -276,7 +273,8 @@
         sourceparams['parser'] = self
         try:
             eid = session.repo.extid2eid(source, str(uri), etype, session,
-                                   sourceparams=sourceparams)
+                                         complete=False,
+                                         sourceparams=sourceparams)
         except ValidationError, ex:
             self.source.error('error while creating %s: %s', etype, ex)
             return None
--- a/sobjects/test/unittest_parsers.py	Tue Jul 26 16:34:42 2011 +0200
+++ b/sobjects/test/unittest_parsers.py	Tue Jul 26 16:35:10 2011 +0200
@@ -256,6 +256,18 @@
         self.assertEqual(user.cwuri, 'http://pouet.org/5')
         self.assertEqual(user.cw_source[0].name, 'myfeed')
 
+    def test_missing_fti_attribute(self):
+        dfsource = self.repo.sources_by_uri['myfeed']
+        session = self.repo.internal_session()
+        parser = dfsource._get_parser(session)
+        dfsource.process_urls(parser, ['''
+<rset size="1">
+ <Card eid="50" cwuri="http://pouet.org/50" cwsource="system">
+  <title>how-to</title>
+ </Card>
+</rset>
+'''], raise_on_error=True)
+
 if __name__ == '__main__':
     from logilab.common.testlib import unittest_main
     unittest_main()