mirror of https://github.com/django/django.git
Fixed #28950 -- Fixed ArrayField.has_changed() for empty values.
This commit is contained in:
parent
e67dc0fbb2
commit
6a1957bb98
|
@ -91,6 +91,16 @@ class SimpleArrayField(forms.CharField):
|
|||
if errors:
|
||||
raise ValidationError(errors)
|
||||
|
||||
def has_changed(self, initial, data):
|
||||
try:
|
||||
value = self.to_python(data)
|
||||
except ValidationError:
|
||||
pass
|
||||
else:
|
||||
if initial in self.empty_values and value in self.empty_values:
|
||||
return False
|
||||
return super().has_changed(initial, data)
|
||||
|
||||
|
||||
class SplitArrayWidget(forms.Widget):
|
||||
template_name = 'postgres/widgets/split_array.html'
|
||||
|
|
|
@ -760,6 +760,14 @@ class TestSimpleFormField(PostgreSQLTestCase):
|
|||
self.assertIs(field.has_changed([1, 2], '1,2,3'), True)
|
||||
self.assertIs(field.has_changed([1, 2], 'a,b'), True)
|
||||
|
||||
def test_has_changed_empty(self):
|
||||
field = SimpleArrayField(forms.CharField())
|
||||
self.assertIs(field.has_changed(None, None), False)
|
||||
self.assertIs(field.has_changed(None, ''), False)
|
||||
self.assertIs(field.has_changed(None, []), False)
|
||||
self.assertIs(field.has_changed([], None), False)
|
||||
self.assertIs(field.has_changed([], ''), False)
|
||||
|
||||
|
||||
class TestSplitFormField(PostgreSQLTestCase):
|
||||
|
||||
|
|
Loading…
Reference in New Issue