#20368: MemoryError can block rendering of traceback page
--------------------------------------+------------------------------------
     Reporter:  ironfroggy            |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  new
    Component:  Template system       |                  Version:  1.3
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  1                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  1
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by wdoekes):

 Here, my fix from #20534:

 {{{
 --- django/views/debug.py.orig  2013-05-31 13:02:36.807798172 +0200
 +++ django/views/debug.py       2013-05-31 13:01:52.555274822 +0200
 @@ -244,7 +244,17 @@ class ExceptionReporter(object):
          frames = self.get_traceback_frames()
          for i, frame in enumerate(frames):
              if 'vars' in frame:
 -                frame['vars'] = [(k, force_escape(pprint(v))) for k, v in
 frame['vars']]
 +                vars = []
 +                for k, v in frame['vars']:
 +                    v = pprint(v)
 +                    # The force_escape filter assume unicode, make sure
 that works
 +                    if isinstance(v, str):
 +                        v = v.decode('utf-8', 'replace')  # don't choke
 on non-utf-8 input
 +                    # You may be looking at large blobs of data, trim it
 +                    if len(v) > 4096:
 +                        v = u'%s... <trimmed %d bytes string>' %
 (v[0:4096], len(v))
 +                    vars.append((k, force_escape(v)))
 +                frame['vars'] = vars
              frames[i] = frame

          unicode_hint = ''
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/20368#comment:8>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/068.afb8fd47c0cc835680f3e8f8d7ef13f9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to