Kaydet (Commit) cb844497 authored tarafından Claude Paroz's avatar Claude Paroz

Fixed #22097 -- Fixed change detection for TypedChoiceField

Thanks Igor Mitrenko for the report.
üst 821fc925
...@@ -191,6 +191,8 @@ class Field(object): ...@@ -191,6 +191,8 @@ class Field(object):
initial_value = initial if initial is not None else '' initial_value = initial if initial is not None else ''
try: try:
data = self.to_python(data) data = self.to_python(data)
if hasattr(self, '_coerce'):
data = self._coerce(data)
except ValidationError: except ValidationError:
return True return True
data_value = data if data is not None else '' data_value = data if data is not None else ''
......
...@@ -961,6 +961,7 @@ class FieldsTests(SimpleTestCase): ...@@ -961,6 +961,7 @@ class FieldsTests(SimpleTestCase):
# has_changed should not trigger required validation # has_changed should not trigger required validation
f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int, required=True) f = TypedChoiceField(choices=[(1, "+1"), (-1, "-1")], coerce=int, required=True)
self.assertFalse(f._has_changed(None, '')) self.assertFalse(f._has_changed(None, ''))
self.assertFalse(f._has_changed(1, '1'))
def test_typedchoicefield_special_coerce(self): def test_typedchoicefield_special_coerce(self):
""" """
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment