summaryrefslogtreecommitdiff
path: root/django/contrib/postgres/forms
diff options
context:
space:
mode:
Diffstat (limited to 'django/contrib/postgres/forms')
-rw-r--r--django/contrib/postgres/forms/hstore.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/django/contrib/postgres/forms/hstore.py b/django/contrib/postgres/forms/hstore.py
index 3dc70ab2ab..bf562c0e8f 100644
--- a/django/contrib/postgres/forms/hstore.py
+++ b/django/contrib/postgres/forms/hstore.py
@@ -23,13 +23,14 @@ class HStoreField(forms.CharField):
def to_python(self, value):
if not value:
return {}
- try:
- value = json.loads(value)
- except ValueError:
- raise ValidationError(
- self.error_messages['invalid_json'],
- code='invalid_json',
- )
+ if not isinstance(value, dict):
+ try:
+ value = json.loads(value)
+ except ValueError:
+ raise ValidationError(
+ self.error_messages['invalid_json'],
+ code='invalid_json',
+ )
# Cast everything to strings for ease.
for key, val in value.items():
value[key] = six.text_type(val)