[dataimport] Add safety belt on "gen_rtype" in MetaGenerator, closes #3712892 stable
authorVincent Michel <vincent.michel@logilab.fr>
Mon, 07 Apr 2014 08:46:41 +0000
branchstable
changeset 9697 d96b5e72717c
parent 9696 4de6e73f580d
child 9698 737983d87497
[dataimport] Add safety belt on "gen_rtype" in MetaGenerator, closes #3712892 Some cubes may well add to the META_RTYPES set, hence crashing the gen_<somecubemeta> call.
dataimport.py
--- a/dataimport.py	Mon Apr 07 08:44:56 2014 +0000
+++ b/dataimport.py	Mon Apr 07 08:46:41 2014 +0000
@@ -860,30 +860,38 @@
         del entity.cw_extra_kwargs
         entity.cw_edited = EditedEntity(entity)
         for attr in self.etype_attrs:
-            entity.cw_edited.edited_attribute(attr, self.generate(entity, attr))
+            genfunc = self.generate(attr)
+            if genfunc:
+                entity.cw_edited.edited_attribute(attr, genfunc(entity))
         rels = {}
         for rel in self.etype_rels:
-            rels[rel] = self.generate(entity, rel)
+            genfunc = self.generate(rel)
+            if genfunc:
+                rels[rel] = genfunc(entity)
         return entity, rels
 
     def init_entity(self, entity):
         entity.eid = self.source.create_eid(self.session)
         for attr in self.entity_attrs:
-            entity.cw_edited.edited_attribute(attr, self.generate(entity, attr))
+            genfunc = self.generate(attr)
+            if genfunc:
+                entity.cw_edited.edited_attribute(attr, genfunc(entity))
 
-    def generate(self, entity, rtype):
-        return getattr(self, 'gen_%s' % rtype)(entity)
+    def generate(self, rtype):
+        return getattr(self, 'gen_%s' % rtype, None)
 
     def gen_cwuri(self, entity):
         return u'%s%s' % (self.baseurl, entity.eid)
 
     def gen_creation_date(self, entity):
         return self.time
+
     def gen_modification_date(self, entity):
         return self.time
 
     def gen_created_by(self, entity):
         return self.session.user.eid
+
     def gen_owned_by(self, entity):
         return self.session.user.eid