[dataimport] Restore handling of Binary in ExtEntity's values
Broken since 62a7100d774b.
Closes #13973741.
--- a/cubicweb/dataimport/importer.py Tue Jun 28 15:01:40 2016 +0200
+++ b/cubicweb/dataimport/importer.py Wed Jun 29 09:12:02 2016 +0200
@@ -216,7 +216,9 @@
if (rschema.final and eschema.has_metadata(rtype, 'format')
and not rtype + '_format' in entity_dict):
entity_dict[rtype + '_format'] = u'text/plain'
- if rschema.final and eschema.rdef(rtype).object.type == 'Bytes':
+ if (rschema.final
+ and eschema.rdef(rtype).object.type == 'Bytes'
+ and not isinstance(entity_dict[rtype], Binary)):
entity_dict[rtype] = Binary(entity_dict[rtype])
else:
del entity_dict[key]
--- a/cubicweb/dataimport/test/unittest_importer.py Tue Jun 28 15:01:40 2016 +0200
+++ b/cubicweb/dataimport/test/unittest_importer.py Wed Jun 29 09:12:02 2016 +0200
@@ -18,7 +18,7 @@
from logilab.common.testlib import TestCase, unittest_main
-from cubicweb import ValidationError
+from cubicweb import Binary, ValidationError
from cubicweb.devtools.testlib import CubicWebTC
from cubicweb.dataimport import RQLObjectStore, ucsvreader
from cubicweb.dataimport.importer import (ExtEntity, ExtEntitiesImporter, RelationMapping,
@@ -74,6 +74,18 @@
entity = cnx.find('Personne').one()
self.assertEqual(entity.photo.getvalue(), b'poilu')
+ def test_binary_in_values(self):
+ with self.admin_access.repo_cnx() as cnx:
+ importer = self.importer(cnx)
+ # Use a list to put a Binary in "values" (since Binary is not
+ # hashable, a set cannot be used).
+ personne = ExtEntity('Personne', 1, {'photo': [Binary(b'poilu')],
+ 'nom': set([u'alf'])})
+ importer.import_entities([personne])
+ cnx.commit()
+ entity = cnx.find('Personne').one()
+ self.assertEqual(entity.photo.getvalue(), b'poilu')
+
def test_import_missing_required_attribute(self):
"""Check import of ext entity with missing required attribute"""
with self.admin_access.repo_cnx() as cnx: