Fixed #25597 -- Fixed crash with SplitArrayField and IntegerField on invalid value.

This commit is contained in:
Tim Graham 2015-10-26 19:37:47 -04:00
parent 9c5e272860
commit 1f07da3e29
3 changed files with 9 additions and 1 deletions

View File

@ -166,7 +166,7 @@ class SplitArrayField(forms.Field):
errors.append(None) errors.append(None)
except ValidationError as error: except ValidationError as error:
errors.append(ValidationError( errors.append(ValidationError(
string_concat(self.error_messages['item_invalid'], error.message), string_concat(self.error_messages['item_invalid'], ' '.join(error.messages)),
code='item_invalid', code='item_invalid',
params={'nth': i}, params={'nth': i},
)) ))

View File

@ -38,3 +38,6 @@ Bugfixes
* Fixed a typo in the name of the `strictly_above` PostGIS lookup * Fixed a typo in the name of the `strictly_above` PostGIS lookup
(:ticket:`25592`). (:ticket:`25592`).
* Fixed crash with ``contrib.postgres.forms.SplitArrayField`` and
``IntegerField`` on invalid value (:ticket:`25597`).

View File

@ -509,6 +509,11 @@ class TestSplitFormField(PostgreSQLTestCase):
self.assertFalse(form.is_valid()) self.assertFalse(form.is_valid())
self.assertEqual(form.errors, {'array': ['Item 2 in the array did not validate: This field is required.']}) self.assertEqual(form.errors, {'array': ['Item 2 in the array did not validate: This field is required.']})
def test_invalid_integer(self):
msg = 'Item 1 in the array did not validate: Ensure this value is less than or equal to 100.'
with self.assertRaisesMessage(exceptions.ValidationError, msg):
SplitArrayField(forms.IntegerField(max_value=100), size=2).clean([0, 101])
def test_rendering(self): def test_rendering(self):
class SplitForm(forms.Form): class SplitForm(forms.Form):
array = SplitArrayField(forms.CharField(), size=3) array = SplitArrayField(forms.CharField(), size=3)