# HG changeset patch # User julien tayon # Date 1558428608 -7200 # Node ID ba5231e1aa45614706e8675a5822eb874d230923 # Parent 3f125fdbcd7013b4f6e45f835c821e75065345ed [dataimport] Fix case when extid is text in use_extid_as_cwuri() Extid can be bytes or text. This avoid AttributeError: 'str' object has no attribute 'decode' diff -r 3f125fdbcd70 -r ba5231e1aa45 cubicweb/dataimport/importer.py --- a/cubicweb/dataimport/importer.py Thu May 16 14:26:38 2019 +0200 +++ b/cubicweb/dataimport/importer.py Tue May 21 10:50:08 2019 +0200 @@ -30,6 +30,8 @@ from collections import defaultdict import logging +import six + from logilab.mtconverter import xml_escape from cubicweb import Binary @@ -71,7 +73,10 @@ def use_extid_as_cwuri_filter(extentities): for extentity in extentities: if extentity.extid not in extid2eid: - extentity.values.setdefault('cwuri', set([extentity.extid.decode('utf-8')])) + cwuri = extentity.extid + if isinstance(cwuri, six.binary_type): + cwuri = cwuri.decode('utf-8') + extentity.values.setdefault('cwuri', set([cwuri])) yield extentity return use_extid_as_cwuri_filter diff -r 3f125fdbcd70 -r ba5231e1aa45 cubicweb/dataimport/test/unittest_importer.py --- a/cubicweb/dataimport/test/unittest_importer.py Thu May 16 14:26:38 2019 +0200 +++ b/cubicweb/dataimport/test/unittest_importer.py Tue May 21 10:50:08 2019 +0200 @@ -196,6 +196,12 @@ personne.values.pop('cwuri') list(set_cwuri((personne,))) self.assertNotIn('cwuri', personne.values) + personne = ExtEntity('Personne', u'ééé', {}) + mapping = {} + set_cwuri = use_extid_as_cwuri(mapping) + list(set_cwuri((personne,))) + self.assertIn('cwuri', personne.values) + self.assertEqual(personne.values['cwuri'], set([u'ééé'])) class DropExtraValuesTC(CubicWebTC):