diff options
| author | Carl Meyer <carl@oddbird.net> | 2011-10-28 14:38:41 +0000 |
|---|---|---|
| committer | Carl Meyer <carl@oddbird.net> | 2011-10-28 14:38:41 +0000 |
| commit | 7a718f0f3a9d08b2f8159cdb8b665e5b84cab83e (patch) | |
| tree | b5329f20dcf3bf349249dffd3fea6c9b411496bb | |
| parent | b87114962fa4d5dd4338b763b724f9836a31f63a (diff) | |
Fixed #17127 -- Made field validators list independent per form instance. Thanks claudep for report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17046 bcc190cf-cafb-0310-a4f2-bffc1f526a37
| -rw-r--r-- | django/forms/fields.py | 1 | ||||
| -rw-r--r-- | tests/regressiontests/forms/tests/forms.py | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/django/forms/fields.py b/django/forms/fields.py index 8e727b4abb..0c598dd672 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -178,6 +178,7 @@ class Field(object): result = copy.copy(self) memo[id(self)] = result result.widget = copy.deepcopy(self.widget, memo) + result.validators = self.validators[:] return result class CharField(Field): diff --git a/tests/regressiontests/forms/tests/forms.py b/tests/regressiontests/forms/tests/forms.py index 91db44949c..a37cc2e3cb 100644 --- a/tests/regressiontests/forms/tests/forms.py +++ b/tests/regressiontests/forms/tests/forms.py @@ -789,6 +789,19 @@ class FormsTestCase(TestCase): f = Person() self.assertEqual(f['gender'].field.choices, [('f', 'Female'), ('m', 'Male')]) + def test_validators_independence(self): + """ Test that we are able to modify a form field validators list without polluting + other forms """ + from django.core.validators import MaxValueValidator + class MyForm(Form): + myfield = CharField(max_length=25) + + f1 = MyForm() + f2 = MyForm() + + f1.fields['myfield'].validators[0] = MaxValueValidator(12) + self.assertFalse(f1.fields['myfield'].validators[0] == f2.fields['myfield'].validators[0]) + def test_hidden_widget(self): # HiddenInput widgets are displayed differently in the as_table(), as_ul()) # and as_p() output of a Form -- their verbose names are not displayed, and a |
