[1.10.x] Fixed #26672 -- Fixed HStoreField to raise ValidationError instead of crashing on non-dict JSON input.

Backport of f6517a5335 from master
This commit is contained in:
Brad Melin 2016-05-29 14:17:07 +02:00 committed by Tim Graham
parent 5641a80d49
commit 3eb31867bb
4 changed files with 22 additions and 1 deletions

View file

@ -208,6 +208,13 @@ class TestFormField(PostgreSQLTestCase):
self.assertEqual(cm.exception.messages[0], 'Could not load JSON data.')
self.assertEqual(cm.exception.code, 'invalid_json')
def test_non_dict_json(self):
field = forms.HStoreField()
msg = 'Input must be a JSON dictionary.'
with self.assertRaisesMessage(exceptions.ValidationError, msg) as cm:
field.clean('["a", "b", 1]')
self.assertEqual(cm.exception.code, 'invalid_format')
def test_not_string_values(self):
field = forms.HStoreField()
value = field.clean('{"a": 1}')