From f6517a5335ccc4858ee540548a1bd162bec36c46 Mon Sep 17 00:00:00 2001 From: Brad Melin Date: Sun, 29 May 2016 14:17:07 +0200 Subject: Fixed #26672 -- Fixed HStoreField to raise ValidationError instead of crashing on non-dict JSON input. --- tests/postgres_tests/test_hstore.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'tests/postgres_tests') diff --git a/tests/postgres_tests/test_hstore.py b/tests/postgres_tests/test_hstore.py index 8ebd757098..b927d8e19f 100644 --- a/tests/postgres_tests/test_hstore.py +++ b/tests/postgres_tests/test_hstore.py @@ -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}') -- cgit v1.3