Code

Opened 5 years ago

Closed 2 years ago

#11970 closed Bug (fixed)

JSON Deserialiser throws ValueError on malformed input

Reported by: boxm Owned by: nobody
Component: Core (Serialization) Version: master
Severity: Normal Keywords:
Cc: boxm 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 boxm 5 years ago.
Fix for problem
11970-with-test.diff (2.1 KB) - added by claudep 3 years ago.
Same patch with tests
11970-with-test2.diff (2.1 KB) - added by claudep 3 years ago.
Fixed missing options parameter
11970-with-test3.diff (2.5 KB) - added by claudep 3 years ago.
Updated to current trunk

Download all attachments as: .zip

Change History (13)

Changed 5 years ago by boxm

Fix for problem

comment:1 Changed 5 years ago by boxm

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 4 years ago by russellm

  • Needs tests set
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 3 years ago by boxm

  • Cc boxm added

comment:4 Changed 3 years ago by julien

  • Severity set to Normal
  • Type set to Bug

Changed 3 years ago by claudep

Same patch with tests

comment:5 Changed 3 years ago by claudep

  • Easy pickings unset
  • Needs tests unset
  • Version changed from 1.1 to SVN

comment:6 Changed 3 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 3 years ago by claudep

Fixed missing options parameter

comment:7 Changed 3 years ago by claudep

  • Patch needs improvement unset

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

Changed 3 years ago by claudep

Updated to current trunk

comment:8 Changed 2 years ago by lrekucki

  • Triage Stage changed from Accepted to Ready for checkin

comment:9 Changed 2 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

In [17469]:

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.