Opened 15 years ago

Closed 15 years ago

Last modified 13 years ago

#10954 closed (fixed)

LazyEncoder in serialization docs is incorrect

Reported by: Glenn Maynard Owned by: nobody
Component: Documentation Version: dev
Severity: Keywords:
Cc: 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

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 15 years ago.
If only the obvious worked: super(self)…

Download all attachments as: .zip

Change History (6)

comment:1 by Alex Gaynor, 15 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

That should be super(LazyEncoder

by Glenn Maynard, 15 years ago

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

comment:2 by Alex Gaynor, 15 years ago

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

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

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 by Russell Keith-Magee, 15 years ago

(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 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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