Opened 7 years ago

Closed 5 years ago

#11970 closed Bug (fixed)

JSON Deserialiser throws ValueError on malformed input

Reported by: Malcolm Box Owned by: nobody
Component: Core (Serialization) Version: master
Severity: Normal Keywords:
Cc: Malcolm Box Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

/core/serializers/json.py Deserializer uses simplejson to parse the input string. If this input is malformed, then simplejson throws a ValueError exception.

However, the serializer interface appears (see XML & base.py) that it should raise a base.DeserializationError when deserialization fails, not a ValueError. Users of the deserializer (e.g. django-restapi) then fail to handle the ValueError, resulting in Internal Server (500) errors.

The fix is to catch ValueError in json.py (around line 40) and re-raise as a DeserializationError.

Simple patch attached.

Attachments (4)

patch.diff (1.1 KB) - added by Malcolm Box 7 years ago.
Fix for problem
11970-with-test.diff (2.1 KB) - added by Claude Paroz 6 years ago.
Same patch with tests
11970-with-test2.diff (2.1 KB) - added by Claude Paroz 5 years ago.
Fixed missing options parameter
11970-with-test3.diff (2.5 KB) - added by Claude Paroz 5 years ago.
Updated to current trunk

Download all attachments as: .zip

Change History (13)

Changed 7 years ago by Malcolm Box

Attachment: patch.diff added

Fix for problem

comment:1 Changed 7 years ago by Malcolm Box

Has patch: set

comment:2 Changed 7 years ago by Russell Keith-Magee

Needs tests: set
Triage Stage: UnreviewedAccepted

comment:3 Changed 6 years ago by Malcolm Box

Cc: Malcolm Box added

comment:4 Changed 6 years ago by Julien Phalip

Severity: Normal
Type: Bug

Changed 6 years ago by Claude Paroz

Attachment: 11970-with-test.diff added

Same patch with tests

comment:5 Changed 6 years ago by Claude Paroz

Easy pickings: unset
Needs tests: unset
Version: 1.1SVN

comment:6 Changed 5 years ago by anonymous

Patch needs improvement: set
UI/UX: unset

This is causing a test to fail related to fixtures:

FAIL: test_fixture_loading (regressiontests.multiple_database.tests.FixtureTestCase)
Multi-db fixtures are loaded correctly
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/admin/Projects/django/django-git/tests/regressiontests/multiple_database/tests.py", line 1639, in test_fixture_loading
    self.fail('"Dive into Python" should exist on other database')
AssertionError: "Dive into Python" should exist on other database

----------------------------------------------------------------------

Changed 5 years ago by Claude Paroz

Attachment: 11970-with-test2.diff added

Fixed missing options parameter

comment:7 Changed 5 years ago by Claude Paroz

Patch needs improvement: unset

Sorry, there was an error in the previous patch (missing **options). Fixed.

Changed 5 years ago by Claude Paroz

Attachment: 11970-with-test3.diff added

Updated to current trunk

comment:8 Changed 5 years ago by Łukasz Rekucki

Triage Stage: AcceptedReady for checkin

comment:9 Changed 5 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

In [17469]:

Fixed #11970 -- Wrapped the exception happening during deserialization in DeserializationError exceptions. Thanks, Claude Paroz.

Note: See TracTickets for help on using tickets.
Back to Top