From 229582db81ea97e3973f8771a488195da19ec496 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 23 Feb 2021 16:03:07 +0100 Subject: [PATCH] csv_import: ignore empty role values (#50158) --- src/authentic2/csv_import.py | 2 ++ tests/test_csv_import.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/authentic2/csv_import.py b/src/authentic2/csv_import.py index 2c056ea6e..2cecd1c63 100644 --- a/src/authentic2/csv_import.py +++ b/src/authentic2/csv_import.py @@ -727,6 +727,8 @@ class UserCsvImporter(object): return success def add_role(self, cell, user, do_clear=False): + if not cell.value.strip(): + return True try: if cell.header.name == ROLE_NAME: role = Role.objects.get(name=cell.value, ou=self.ou) diff --git a/tests/test_csv_import.py b/tests/test_csv_import.py index 921e9747b..fc3af0144 100644 --- a/tests/test_csv_import.py +++ b/tests/test_csv_import.py @@ -495,6 +495,12 @@ tnoel@entrouvert.com,test_name''' assert importer.has_errors assert importer.errors[0].code == 'invalid-role-column' + # empty role name doesn't raise error + content_name_error = '\n'.join((base_header + '_role_name', base_user + '')) + importer = user_csv_importer_factory(content_name_error) + assert importer.run() + assert not importer.has_errors + def test_csv_registration_options(profile, user_csv_importer_factory): content = '''email key,first_name,last_name,@registration