csv_import: do not create userexternalid on update (#34258)

This commit is contained in:
Benjamin Dauvergne 2019-06-24 11:49:58 +02:00
parent 1ecaa8ccaf
commit c8e0052ed3
2 changed files with 12 additions and 3 deletions

View File

@ -281,8 +281,13 @@ class UserCsvImporter(object):
try:
with atomic():
for row in self.rows:
if not self.do_import_row(row, unique_map):
try:
if not self.do_import_row(row, unique_map):
self.rows_with_errors += 1
except CancelImport:
self.rows_with_errors += 1
if row.errors:
self.has_errors = True
if simulate:
raise Simulate
except Simulate:
@ -554,7 +559,7 @@ class UserCsvImporter(object):
user.save()
if header_key.name == SOURCE_ID:
if header_key.name == SOURCE_ID and row.action == 'create':
try:
UserExternalId.objects.create(user=user,
source=source_name,
@ -562,7 +567,7 @@ class UserCsvImporter(object):
except IntegrityError:
# should never happen since we have a unique index...
source_full_id = '%s.%s' % (source_name, source_id)
self.errors.append(
row.errors.append(
Error('external-id-already-exist',
_('External id "%s" already exists') % source_full_id))
raise CancelImport

View File

@ -385,3 +385,7 @@ app1,2,tnoel@entrouvert.com,Thomas,Noël,1234
assert thomas.last_name == 'Noël'
assert thomas.attributes.last_name == 'Noël'
assert thomas.attributes.phone == '1234'
importer = user_csv_importer_factory(content)
assert importer.run(), importer.errors
assert not importer.has_errors