# HG changeset patch # User Sylvain Thénault # Date 1492585510 -7200 # Node ID d13fc09301bd0892eb45a7109b87aa0f8cca4d1e # Parent 8bb323eb685948b6d823791d686c4169358467f4 [dataimport] Add explanation about why external entities can't be inserted By default after the import processed the importer indicates which external entities can't be inserted because they are missing dependency data (other entities, used in inlined or mandatory relations). It usually helps there to find out which extids / relations are missing, so add this to the log. diff -r 8bb323eb6859 -r d13fc09301bd cubicweb/dataimport/importer.py --- a/cubicweb/dataimport/importer.py Thu Apr 20 17:22:36 2017 +0200 +++ b/cubicweb/dataimport/importer.py Wed Apr 19 09:05:10 2017 +0200 @@ -253,6 +253,21 @@ entity_dict[rtype] = extid2eid[entity_dict[rtype]] return True + def why_not_ready(self, extid2eid): + """Return some text explaining why this ext entity is not ready. + """ + assert self._schema, 'prepare() method should be called first on %s' % self + # as .prepare has been called, we know that .values only contains subject relation *type* as + # key (no more (rtype, role) tuple) + schema = self._schema + entity_dict = self.values + for rtype in entity_dict: + rschema = schema.rschema(rtype) + if not rschema.final: + if entity_dict[rtype] not in extid2eid: + return u'inlined relation %s is not present (%s)' % (rtype, entity_dict[rtype]) + raise AssertionError('this external entity seems actually ready for insertion') + class ExtEntitiesImporter(object): """This class is responsible for importing externals entities, that is instances of @@ -413,7 +428,8 @@ "missing data?"] for ext_entities in queue.values(): for ext_entity in ext_entities: - msgs.append(str(ext_entity)) + msg = '{}: {}'.format(ext_entity, ext_entity.why_not_ready(self.extid2eid)) + msgs.append(msg) map(error, msgs) if self.raise_on_error: raise Exception('\n'.join(msgs))