Opened 8 years ago

Closed 8 years ago

Last modified 5 years ago

#10954 closed (fixed)

LazyEncoder in serialization docs is incorrect

Reported by: Glenn Maynard Owned by: nobody
Component: Documentation Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

http://docs.djangoproject.com/en/dev/topics/serialization:

from django.utils.functional import Promise
from django.utils.encoding import force_unicode

class LazyEncoder(simplejson.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, Promise):
            return force_unicode(obj)
        return obj

This causes "object is not JSON serializable" errors to be turned into "ValueError: Circular reference detected".

Attachments (1)

fix-serializer-example-code.diff (526 bytes) - added by Glenn Maynard 8 years ago.
If only the obvious worked: super(self)…

Download all attachments as: .zip

Change History (6)

comment:1 Changed 8 years ago by Alex Gaynor

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

That should be super(LazyEncoder

Changed 8 years ago by Glenn Maynard

If only the obvious worked: super(self)...

comment:2 Changed 8 years ago by Alex Gaynor

milestone: 1.1
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:3 Changed 8 years ago by Russell Keith-Magee

Resolution: fixed
Status: newclosed

(In [10654]) Fixed #10954 -- Corrected error in docs example describing extending the JSON serializer. Thanks to Glenn for the report.

comment:4 Changed 8 years ago by Russell Keith-Magee

(In [10656]) [1.0.X] Fixed #10954 -- Corrected error in docs example describing extending the JSON serializer. Thanks to Glenn for the report.

Merge of r10654 from trunk.

comment:5 Changed 5 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

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