diff --git a/modoboa/admin/management/commands/subcommands/_repair.py b/modoboa/admin/management/commands/subcommands/_repair.py index 213f40313..029e72ae1 100644 --- a/modoboa/admin/management/commands/subcommands/_repair.py +++ b/modoboa/admin/management/commands/subcommands/_repair.py @@ -62,7 +62,12 @@ class Repair(BaseCommand): elif isinstance(obj, models.DomainAlias): admin = obj.target.admins.first() else: - admin = obj.domain.admins.first() + if obj.domain: + admin = obj.domain.admins.first() + else: + # Alias is an internal alias for domain alias + # we don't care if it's not owned + continue if not admin: # domain has no admin. use the first superuser found admin = User.objects.filter(is_superuser=True, diff --git a/modoboa/admin/tests/test_repair.py b/modoboa/admin/tests/test_repair.py index 1ea383015..e93efa932 100644 --- a/modoboa/admin/tests/test_repair.py +++ b/modoboa/admin/tests/test_repair.py @@ -39,3 +39,8 @@ class RepairTestCase(ModoTestCase): management.call_command("modo", "repair", "--quiet", "--dry-run") # assert its not fixed self.assertIs(get_object_owner(mbox), None) + + def test_management_command_with_nul_domain(self): + """ Just assume nothing raise when an alias has no domain""" + models.Alias.objects.create(address='@modoboa.xxx') + management.call_command("modo", "repair", "--quiet")