1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

Fixed #12596. Calling super from a ModelForm's clean method is once again optional. Failing to call super only skips unique validation as documented. Thanks for the initial patch and tests, carljm.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@12269 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Joseph Kocherhans
2010-01-21 02:28:03 +00:00
parent 856a39e841
commit 408d431029
3 changed files with 73 additions and 12 deletions

View File

@@ -50,6 +50,27 @@ class UniqueTogetherTests(TestCase):
form = TripleForm({'left': '1', 'middle': '3', 'right': '1'})
self.failUnless(form.is_valid())
class TripleFormWithCleanOverride(forms.ModelForm):
class Meta:
model = Triple
def clean(self):
if not self.cleaned_data['left'] == self.cleaned_data['right']:
raise forms.ValidationError('Left and right should be equal')
return self.cleaned_data
class OverrideCleanTests(TestCase):
def test_override_clean(self):
"""
Regression for #12596: Calling super from ModelForm.clean() should be
optional.
"""
form = TripleFormWithCleanOverride({'left': 1, 'middle': 2, 'right': 1})
self.failUnless(form.is_valid())
# form.instance.left will be None if the instance was not constructed
# by form.full_clean().
self.assertEquals(form.instance.left, 1)
class FPForm(forms.ModelForm):
class Meta:
model = FilePathModel