From 98706bb35e7de0e445cc336f669919047bf46b75 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 20 Jun 2017 15:16:37 -0400 Subject: Refs #27857 -- Replaced json.loads() ValueError exception catching with JSONDecodeError. --- django/contrib/postgres/forms/hstore.py | 2 +- django/contrib/postgres/forms/jsonb.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'django/contrib/postgres/forms') diff --git a/django/contrib/postgres/forms/hstore.py b/django/contrib/postgres/forms/hstore.py index 984227ff71..f5af8f10e3 100644 --- a/django/contrib/postgres/forms/hstore.py +++ b/django/contrib/postgres/forms/hstore.py @@ -28,7 +28,7 @@ class HStoreField(forms.CharField): if not isinstance(value, dict): try: value = json.loads(value) - except ValueError: + except json.JSONDecodeError: raise ValidationError( self.error_messages['invalid_json'], code='invalid_json', diff --git a/django/contrib/postgres/forms/jsonb.py b/django/contrib/postgres/forms/jsonb.py index 2cb6092cb7..158ab8fdb9 100644 --- a/django/contrib/postgres/forms/jsonb.py +++ b/django/contrib/postgres/forms/jsonb.py @@ -29,7 +29,7 @@ class JSONField(forms.CharField): return value try: converted = json.loads(value) - except ValueError: + except json.JSONDecodeError: raise forms.ValidationError( self.error_messages['invalid'], code='invalid', @@ -45,7 +45,7 @@ class JSONField(forms.CharField): return initial try: return json.loads(data) - except ValueError: + except json.JSONDecodeError: return InvalidJSONInput(data) def prepare_value(self, value): -- cgit v1.3