From a735944af7f5aa1c67dd0a89f2e593bb5022fdcf Mon Sep 17 00:00:00 2001 From: Vitor Freitas Date: Sat, 25 May 2019 19:34:29 +0300 Subject: Fix exception when campaign has no mailing list --- colossus/apps/campaigns/forms.py | 2 +- colossus/apps/campaigns/tests/test_views.py | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/colossus/apps/campaigns/forms.py b/colossus/apps/campaigns/forms.py index 6f675cf..3ec7666 100644 --- a/colossus/apps/campaigns/forms.py +++ b/colossus/apps/campaigns/forms.py @@ -72,7 +72,7 @@ class CampaignRecipientsForm(forms.ModelForm): self.fields['tag'].queryset = Tag.objects.filter(mailing_list_id=mailing_list_id).order_by('name') except (ValueError, TypeError): pass - elif self.instance.pk: + elif self.instance.pk and self.instance.mailing_list: self.fields['tag'].queryset = self.instance.mailing_list.tags.order_by('name') diff --git a/colossus/apps/campaigns/tests/test_views.py b/colossus/apps/campaigns/tests/test_views.py index 48f314b..d4525bf 100644 --- a/colossus/apps/campaigns/tests/test_views.py +++ b/colossus/apps/campaigns/tests/test_views.py @@ -92,3 +92,14 @@ class CampaignCreateViewTests(AuthenticatedTestCase): response = self.client.get(self.url) self.assertContains(response, '