From d91cc25a2a43cb2526943dc2285ffe59e38fabfd Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 16 Dec 2015 23:07:17 +0100 Subject: Fixed #25942 -- Fixed TypedChoiceField.has_changed with nullable field This fixes a regression introduced by 871440361. --- django/forms/fields.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'django/forms') diff --git a/django/forms/fields.py b/django/forms/fields.py index 55f225e65b..ac615bbe68 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -181,17 +181,16 @@ class Field(object): """ Return True if data differs from initial. """ - # For purposes of seeing whether something has changed, None is - # the same as an empty string, if the data or initial value we get - # is None, replace it w/ ''. - initial_value = initial if initial is not None else '' try: data = self.to_python(data) if hasattr(self, '_coerce'): - data = self._coerce(data) - initial_value = self._coerce(initial_value) + return self._coerce(data) != self._coerce(initial) except ValidationError: return True + # For purposes of seeing whether something has changed, None is + # the same as an empty string, if the data or initial value we get + # is None, replace it with ''. + initial_value = initial if initial is not None else '' data_value = data if data is not None else '' return initial_value != data_value -- cgit v1.3