Opened 15 years ago

Closed 13 years ago

#11970 closed Bug (fixed)

JSON Deserialiser throws ValueError on malformed input

Reported by: Malcolm Box Owned by: nobody
Component: Core (Serialization) Version: dev
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 15 years ago.
Fix for problem
11970-with-test.diff (2.1 KB ) - added by Claude Paroz 14 years ago.
Same patch with tests
11970-with-test2.diff (2.1 KB ) - added by Claude Paroz 13 years ago.
Fixed missing options parameter
11970-with-test3.diff (2.5 KB ) - added by Claude Paroz 13 years ago.
Updated to current trunk

Download all attachments as: .zip

Change History (13)

by Malcolm Box, 15 years ago

Attachment: patch.diff added

Fix for problem

comment:1 by Malcolm Box, 15 years ago

Has patch: set

comment:2 by Russell Keith-Magee, 15 years ago

Needs tests: set
Triage Stage: UnreviewedAccepted

comment:3 by Malcolm Box, 14 years ago

Cc: Malcolm Box added

comment:4 by Julien Phalip, 14 years ago

Severity: Normal
Type: Bug

by Claude Paroz, 14 years ago

Attachment: 11970-with-test.diff added

Same patch with tests

comment:5 by Claude Paroz, 14 years ago

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

comment:6 by anonymous, 13 years ago

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

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

by Claude Paroz, 13 years ago

Attachment: 11970-with-test2.diff added

Fixed missing options parameter

comment:7 by Claude Paroz, 13 years ago

Patch needs improvement: unset

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

by Claude Paroz, 13 years ago

Attachment: 11970-with-test3.diff added

Updated to current trunk

comment:8 by Łukasz Rekucki, 13 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Jannis Leidel, 13 years ago

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