diff options
| author | quaspas <daniel.quattro@gmail.com> | 2016-03-12 16:44:39 -0500 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-03-12 17:22:25 -0500 |
| commit | 91f87b8f91f5f8d01ac4b814dce218be27f56ab2 (patch) | |
| tree | ae0e9b8992005b5384e02baf0acb1a069f8032df | |
| parent | ab8af342b1d5dbe40502f1adfe8c7a6b746c8004 (diff) | |
Fixed #26283 -- Fixed removal of trailing nulls for SplitArrayField.
| -rw-r--r-- | django/contrib/postgres/forms/array.py | 2 | ||||
| -rw-r--r-- | tests/postgres_tests/test_array.py | 14 |
2 files changed, 15 insertions, 1 deletions
diff --git a/django/contrib/postgres/forms/array.py b/django/contrib/postgres/forms/array.py index ea466bc1ea..dd9ac1178e 100644 --- a/django/contrib/postgres/forms/array.py +++ b/django/contrib/postgres/forms/array.py @@ -183,7 +183,7 @@ class SplitArrayField(forms.Field): null_index = i else: break - if null_index: + if null_index is not None: cleaned_data = cleaned_data[:null_index] errors = errors[:null_index] errors = list(filter(None, errors)) diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index f5c333e56f..670c98e7a7 100644 --- a/tests/postgres_tests/test_array.py +++ b/tests/postgres_tests/test_array.py @@ -663,6 +663,20 @@ class TestSplitFormField(PostgreSQLTestCase): self.assertTrue(form.is_valid(), form.errors) self.assertEqual(form.cleaned_data, {'array': ['a', '', 'b']}) + def test_remove_trailing_nulls_not_required(self): + class SplitForm(forms.Form): + array = SplitArrayField( + forms.CharField(required=False), + size=2, + remove_trailing_nulls=True, + required=False, + ) + + data = {'array_0': '', 'array_1': ''} + form = SplitForm(data) + self.assertTrue(form.is_valid()) + self.assertEqual(form.cleaned_data, {'array': []}) + def test_required_field(self): class SplitForm(forms.Form): array = SplitArrayField(forms.CharField(), size=3) |
