From a417c0efb4b37fe9f59d7b982b2ecf276bf2e306 Mon Sep 17 00:00:00 2001 From: GappleBee Date: Sat, 14 Sep 2024 10:26:12 +0100 Subject: Fixed #35449 -- Fixed validation of array items in SplitArrayField when remove_trailing_nulls=True. --- tests/postgres_tests/test_array.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'tests/postgres_tests/test_array.py') diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index ff0c4aabb1..ea7807687e 100644 --- a/tests/postgres_tests/test_array.py +++ b/tests/postgres_tests/test_array.py @@ -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): class Form(forms.ModelForm): field = SplitArrayField(forms.IntegerField(), required=False, size=2) -- cgit v1.3