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] == '[':
|
if self.change_message and self.change_message[0] == '[':
|
||||||
try:
|
try:
|
||||||
change_message = json.loads(self.change_message)
|
change_message = json.loads(self.change_message)
|
||||||
except ValueError:
|
except json.JSONDecodeError:
|
||||||
return self.change_message
|
return self.change_message
|
||||||
messages = []
|
messages = []
|
||||||
for sub_message in change_message:
|
for sub_message in change_message:
|
||||||
|
|
|
@ -157,7 +157,7 @@ class CookieStorage(BaseStorage):
|
||||||
# If we get here (and the JSON decode works), everything is
|
# If we get here (and the JSON decode works), everything is
|
||||||
# good. In any other case, drop back and return None.
|
# good. In any other case, drop back and return None.
|
||||||
return json.loads(value, cls=MessageDecoder)
|
return json.loads(value, cls=MessageDecoder)
|
||||||
except ValueError:
|
except json.JSONDecodeError:
|
||||||
pass
|
pass
|
||||||
# Mark the data as used (so it gets removed) since something was wrong
|
# Mark the data as used (so it gets removed) since something was wrong
|
||||||
# with the data.
|
# with the data.
|
||||||
|
|
|
@ -28,7 +28,7 @@ class HStoreField(forms.CharField):
|
||||||
if not isinstance(value, dict):
|
if not isinstance(value, dict):
|
||||||
try:
|
try:
|
||||||
value = json.loads(value)
|
value = json.loads(value)
|
||||||
except ValueError:
|
except json.JSONDecodeError:
|
||||||
raise ValidationError(
|
raise ValidationError(
|
||||||
self.error_messages['invalid_json'],
|
self.error_messages['invalid_json'],
|
||||||
code='invalid_json',
|
code='invalid_json',
|
||||||
|
|
|
@ -29,7 +29,7 @@ class JSONField(forms.CharField):
|
||||||
return value
|
return value
|
||||||
try:
|
try:
|
||||||
converted = json.loads(value)
|
converted = json.loads(value)
|
||||||
except ValueError:
|
except json.JSONDecodeError:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
self.error_messages['invalid'],
|
self.error_messages['invalid'],
|
||||||
code='invalid',
|
code='invalid',
|
||||||
|
@ -45,7 +45,7 @@ class JSONField(forms.CharField):
|
||||||
return initial
|
return initial
|
||||||
try:
|
try:
|
||||||
return json.loads(data)
|
return json.loads(data)
|
||||||
except ValueError:
|
except json.JSONDecodeError:
|
||||||
return InvalidJSONInput(data)
|
return InvalidJSONInput(data)
|
||||||
|
|
||||||
def prepare_value(self, value):
|
def prepare_value(self, value):
|
||||||
|
|
|
@ -391,7 +391,7 @@ class ManifestFilesMixin(HashedFilesMixin):
|
||||||
return OrderedDict()
|
return OrderedDict()
|
||||||
try:
|
try:
|
||||||
stored = json.loads(content, object_pairs_hook=OrderedDict)
|
stored = json.loads(content, object_pairs_hook=OrderedDict)
|
||||||
except ValueError:
|
except json.JSONDecodeError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
version = stored.get('version')
|
version = stored.get('version')
|
||||||
|
|
|
@ -708,7 +708,7 @@ class SimpleTestCase(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
data = json.loads(raw)
|
data = json.loads(raw)
|
||||||
except ValueError:
|
except json.JSONDecodeError:
|
||||||
self.fail("First argument is not valid JSON: %r" % raw)
|
self.fail("First argument is not valid JSON: %r" % raw)
|
||||||
if isinstance(expected_data, str):
|
if isinstance(expected_data, str):
|
||||||
try:
|
try:
|
||||||
|
@ -725,12 +725,12 @@ class SimpleTestCase(unittest.TestCase):
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
data = json.loads(raw)
|
data = json.loads(raw)
|
||||||
except ValueError:
|
except json.JSONDecodeError:
|
||||||
self.fail("First argument is not valid JSON: %r" % raw)
|
self.fail("First argument is not valid JSON: %r" % raw)
|
||||||
if isinstance(expected_data, str):
|
if isinstance(expected_data, str):
|
||||||
try:
|
try:
|
||||||
expected_data = json.loads(expected_data)
|
expected_data = json.loads(expected_data)
|
||||||
except ValueError:
|
except json.JSONDecodeError:
|
||||||
self.fail("Second argument is not valid JSON: %r" % expected_data)
|
self.fail("Second argument is not valid JSON: %r" % expected_data)
|
||||||
self.assertNotEqual(data, expected_data, msg=msg)
|
self.assertNotEqual(data, expected_data, msg=msg)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue