diff options
| author | Brad Melin <melinbrad@gmail.com> | 2016-05-29 14:17:07 +0200 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2016-06-02 16:28:01 -0400 |
| commit | f6517a5335ccc4858ee540548a1bd162bec36c46 (patch) | |
| tree | ec9ca118fc59c77a3c05cbef51fab714d6c11410 /django/contrib/postgres/forms | |
| parent | abc522383454493e6341bfe7307143440d9ee7ac (diff) | |
Fixed #26672 -- Fixed HStoreField to raise ValidationError instead of crashing on non-dict JSON input.
Diffstat (limited to 'django/contrib/postgres/forms')
| -rw-r--r-- | django/contrib/postgres/forms/hstore.py | 12 |
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) |
