summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorBrad Melin <melinbrad@gmail.com>2016-05-29 14:17:07 +0200
committerTim Graham <timograham@gmail.com>2016-06-02 16:29:22 -0400
commit3eb31867bb25d462634255e187001c0fffe2a032 (patch)
treefbcfeb7470877b83010d577dcb9435aaadd96f36 /django
parent5641a80d49d31916828ef7478af1800d0469c46a (diff)
[1.10.x] Fixed #26672 -- Fixed HStoreField to raise ValidationError instead of crashing on non-dict JSON input.
Backport of f6517a5335ccc4858ee540548a1bd162bec36c46 from master
Diffstat (limited to 'django')
-rw-r--r--django/contrib/postgres/forms/hstore.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/django/contrib/postgres/forms/hstore.py b/django/contrib/postgres/forms/hstore.py
index bf562c0e8f..4ed99d1fda 100644
--- a/django/contrib/postgres/forms/hstore.py
+++ b/django/contrib/postgres/forms/hstore.py
@@ -9,10 +9,13 @@ __all__ = ['HStoreField']
class HStoreField(forms.CharField):
- """A field for HStore data which accepts JSON input."""
+ """
+ A field for HStore data which accepts dictionary JSON input.
+ """
widget = forms.Textarea
default_error_messages = {
'invalid_json': _('Could not load JSON data.'),
+ 'invalid_format': _('Input must be a JSON dictionary.'),
}
def prepare_value(self, value):
@@ -31,6 +34,13 @@ class HStoreField(forms.CharField):
self.error_messages['invalid_json'],
code='invalid_json',
)
+
+ if not isinstance(value, dict):
+ raise ValidationError(
+ self.error_messages['invalid_format'],
+ code='invalid_format',
+ )
+
# Cast everything to strings for ease.
for key, val in value.items():
value[key] = six.text_type(val)