Browse Source

Fixed #22097 -- Fixed change detection for TypedChoiceField

Thanks Igor Mitrenko for the report.
Claude Paroz 11 years ago
parent
commit
cb844497d0
2 changed files with 3 additions and 0 deletions
  1. 2 0
      django/forms/fields.py
  2. 1 0
      tests/forms_tests/tests/test_fields.py

+ 2 - 0
django/forms/fields.py

@@ -191,6 +191,8 @@ class Field(object):
         initial_value = initial if initial is not None else ''
         try:
             data = self.to_python(data)
+            if hasattr(self, '_coerce'):
+                data = self._coerce(data)
         except ValidationError:
             return True
         data_value = data if data is not None else ''

+ 1 - 0
tests/forms_tests/tests/test_fields.py

@@ -961,6 +961,7 @@ class FieldsTests(SimpleTestCase):
         # has_changed should not trigger required validation
         f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int, required=True)
         self.assertFalse(f._has_changed(None, ''))
+        self.assertFalse(f._has_changed(1, '1'))
 
     def test_typedchoicefield_special_coerce(self):
         """