summaryrefslogtreecommitdiff
path: root/tests/postgres_tests/test_array.py
diff options
context:
space:
mode:
authorGappleBee <irrationalmathematicspro7@gmail.com>2024-09-14 10:26:12 +0100
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2024-10-07 15:36:57 +0200
commita417c0efb4b37fe9f59d7b982b2ecf276bf2e306 (patch)
treefb38db981e754a5a77e7dac39b3724b077175fda /tests/postgres_tests/test_array.py
parent50f89ae850f6b4e35819fe725a08c7e579bfd099 (diff)
Fixed #35449 -- Fixed validation of array items in SplitArrayField when remove_trailing_nulls=True.
Diffstat (limited to 'tests/postgres_tests/test_array.py')
-rw-r--r--tests/postgres_tests/test_array.py16
1 files changed, 16 insertions, 0 deletions
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)