Refs #27003 -- Fixed SimpleArrayField crash on converted values.

This commit is contained in:
Brandon Chinn 2016-11-11 17:07:15 -08:00 committed by Tim Graham
parent 74ed20b49a
commit 6573274161
3 changed files with 9 additions and 1 deletions

View File

@ -110,6 +110,7 @@ answer newbie questions, and generally made Django that much better:
Bouke Haarsma <bouke@haarsma.eu>
Božidar Benko <bbenko@gmail.com>
Brad Melin <melinbrad@gmail.com>
Brandon Chinn <http://brandonchinn178.github.io>
Brant Harris
Brendan Hayward <brendanhayward85@gmail.com>
Brenton Simpson <http://theillustratedlife.com>

View File

@ -35,7 +35,9 @@ class SimpleArrayField(forms.CharField):
return value
def to_python(self, value):
if value:
if isinstance(value, list):
items = value
elif value:
items = value.split(self.delimiter)
else:
items = []

View File

@ -677,6 +677,11 @@ class TestSimpleFormField(PostgreSQLTestCase):
self.assertIsInstance(form_field, SimpleArrayField)
self.assertEqual(form_field.max_length, 4)
def test_already_converted_value(self):
field = SimpleArrayField(forms.CharField())
vals = ['a', 'b', 'c']
self.assertEqual(field.clean(vals), vals)
class TestSplitFormField(PostgreSQLTestCase):