mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #35449 -- Fixed validation of array items in SplitArrayField when remove_trailing_nulls=True.
This commit is contained in:
parent
50f89ae850
commit
a417c0efb4
@ -228,7 +228,7 @@ class SplitArrayField(forms.Field):
|
|||||||
params={"nth": index + 1},
|
params={"nth": index + 1},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
cleaned_data.append(None)
|
cleaned_data.append(item)
|
||||||
else:
|
else:
|
||||||
errors.append(None)
|
errors.append(None)
|
||||||
cleaned_data, null_index = self._remove_trailing_nulls(cleaned_data)
|
cleaned_data, null_index = self._remove_trailing_nulls(cleaned_data)
|
||||||
|
@ -1339,6 +1339,22 @@ class TestSplitFormField(PostgreSQLSimpleTestCase):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_invalid_char_length_with_remove_trailing_nulls(self):
|
||||||
|
field = SplitArrayField(
|
||||||
|
forms.CharField(max_length=2, required=False),
|
||||||
|
size=3,
|
||||||
|
remove_trailing_nulls=True,
|
||||||
|
)
|
||||||
|
with self.assertRaises(exceptions.ValidationError) as cm:
|
||||||
|
field.clean(["abc", "", ""])
|
||||||
|
self.assertEqual(
|
||||||
|
cm.exception.messages,
|
||||||
|
[
|
||||||
|
"Item 1 in the array did not validate: Ensure this value has at most 2 "
|
||||||
|
"characters (it has 3).",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
def test_splitarraywidget_value_omitted_from_data(self):
|
def test_splitarraywidget_value_omitted_from_data(self):
|
||||||
class Form(forms.ModelForm):
|
class Form(forms.ModelForm):
|
||||||
field = SplitArrayField(forms.IntegerField(), required=False, size=2)
|
field = SplitArrayField(forms.IntegerField(), required=False, size=2)
|
||||||
|
Loading…
Reference in New Issue
Block a user