From 75743c189d5138e47fd139b154c42e3bb67361c8 Mon Sep 17 00:00:00 2001 From: Karen Tracey Date: Sat, 28 Apr 2012 19:44:14 -0400 Subject: [PATCH] Fixed #18234: Avoided exception on flatpage add --- django/contrib/flatpages/forms.py | 2 +- django/contrib/flatpages/tests/forms.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/django/contrib/flatpages/forms.py b/django/contrib/flatpages/forms.py index 8ffae833e5..e0a63e4323 100644 --- a/django/contrib/flatpages/forms.py +++ b/django/contrib/flatpages/forms.py @@ -31,7 +31,7 @@ class FlatpageForm(forms.ModelForm): if self.instance.pk: same_url = same_url.exclude(pk=self.instance.pk) - if same_url.filter(sites__in=sites).exists(): + if sites and same_url.filter(sites__in=sites).exists(): for site in sites: if same_url.filter(sites=site).exists(): raise forms.ValidationError( diff --git a/django/contrib/flatpages/tests/forms.py b/django/contrib/flatpages/tests/forms.py index 884c40acc8..eb37e9ec29 100644 --- a/django/contrib/flatpages/tests/forms.py +++ b/django/contrib/flatpages/tests/forms.py @@ -78,3 +78,16 @@ class FlatpageAdminFormTests(TestCase): updated = f.save() self.assertEqual(updated.title, "A test page") + + def test_flatpage_nosites(self): + data = dict(url='/myflatpage1/', **self.form_data) + data.update({'sites': ''}) + + f = FlatpageForm(data=data) + + self.assertFalse(f.is_valid()) + + self.assertEqual( + f.errors, + {'sites': [u'This field is required.']}) +