Refs #27857 -- Replaced json.loads() ValueError exception catching with JSONDecodeError.
This commit is contained in:
parent
cfff2af02b
commit
98706bb35e
|
@ -95,7 +95,7 @@ class LogEntry(models.Model):
|
|||
if self.change_message and self.change_message[0] == '[':
|
||||
try:
|
||||
change_message = json.loads(self.change_message)
|
||||
except ValueError:
|
||||
except json.JSONDecodeError:
|
||||
return self.change_message
|
||||
messages = []
|
||||
for sub_message in change_message:
|
||||
|
|
|
@ -157,7 +157,7 @@ class CookieStorage(BaseStorage):
|
|||
# If we get here (and the JSON decode works), everything is
|
||||
# good. In any other case, drop back and return None.
|
||||
return json.loads(value, cls=MessageDecoder)
|
||||
except ValueError:
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
# Mark the data as used (so it gets removed) since something was wrong
|
||||
# with the data.
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -391,7 +391,7 @@ class ManifestFilesMixin(HashedFilesMixin):
|
|||
return OrderedDict()
|
||||
try:
|
||||
stored = json.loads(content, object_pairs_hook=OrderedDict)
|
||||
except ValueError:
|
||||
except json.JSONDecodeError:
|
||||
pass
|
||||
else:
|
||||
version = stored.get('version')
|
||||
|
|
|
@ -708,7 +708,7 @@ class SimpleTestCase(unittest.TestCase):
|
|||
"""
|
||||
try:
|
||||
data = json.loads(raw)
|
||||
except ValueError:
|
||||
except json.JSONDecodeError:
|
||||
self.fail("First argument is not valid JSON: %r" % raw)
|
||||
if isinstance(expected_data, str):
|
||||
try:
|
||||
|
@ -725,12 +725,12 @@ class SimpleTestCase(unittest.TestCase):
|
|||
"""
|
||||
try:
|
||||
data = json.loads(raw)
|
||||
except ValueError:
|
||||
except json.JSONDecodeError:
|
||||
self.fail("First argument is not valid JSON: %r" % raw)
|
||||
if isinstance(expected_data, str):
|
||||
try:
|
||||
expected_data = json.loads(expected_data)
|
||||
except ValueError:
|
||||
except json.JSONDecodeError:
|
||||
self.fail("Second argument is not valid JSON: %r" % expected_data)
|
||||
self.assertNotEqual(data, expected_data, msg=msg)
|
||||
|
||||
|
|
Loading…
Reference in New Issue