# HG changeset patch # User Denis Laxalde # Date 1467184322 -7200 # Node ID e148b384a782e15fa56bd596c4aa48417b90a598 # Parent 9294fa5bc336da4cae04141052e189d5ce50685b [dataimport] Restore handling of Binary in ExtEntity's values Broken since 62a7100d774b. Closes #13973741. diff -r 9294fa5bc336 -r e148b384a782 cubicweb/dataimport/importer.py --- 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] diff -r 9294fa5bc336 -r e148b384a782 cubicweb/dataimport/test/unittest_importer.py --- 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: