Skip to content

Commit

Permalink
Fixed #17127 -- Made field validators list independent per form insta…
Browse files Browse the repository at this point in the history
…nce. Thanks claudep for report and patch.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17046 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
carljm committed Oct 28, 2011
1 parent b871149 commit 7a718f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions django/forms/fields.py
Expand Up @@ -178,6 +178,7 @@ def __deepcopy__(self, memo):
result = copy.copy(self)
memo[id(self)] = result
result.widget = copy.deepcopy(self.widget, memo)
result.validators = self.validators[:]
return result

class CharField(Field):
Expand Down
13 changes: 13 additions & 0 deletions tests/regressiontests/forms/tests/forms.py
Expand Up @@ -789,6 +789,19 @@ def __init__(self, allow_unspec_gender=False, *args, **kwargs):
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
Expand Down

0 comments on commit 7a718f0

Please sign in to comment.