Code

Opened 5 years ago

Closed 5 years ago

Last modified 3 years ago

#10954 closed (fixed)

LazyEncoder in serialization docs is incorrect

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

Download all attachments as: .zip

Change History (6)

comment:1 Changed 5 years ago by Alex

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement set
  • Triage Stage changed from Unreviewed to Accepted

That should be super(LazyEncoder

Changed 5 years ago by Glenn

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

comment:2 Changed 5 years ago by Alex

  • milestone set to 1.1
  • Patch needs improvement unset
  • Triage Stage changed from Accepted to Ready for checkin

comment:3 Changed 5 years ago by russellm

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

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

comment:4 Changed 5 years ago by russellm

(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 3 years ago by jacob

  • milestone 1.1 deleted

Milestone 1.1 deleted

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.