Edgewall Software
Modify

#13039 closed defect (fixed)

TypeError raised when rendering error with chunked encoding

Reported by: Jun Omae Owned by: Ryan J Ollos
Priority: normal Milestone: 1.3.3
Component: general Version: 1.3dev
Severity: normal Keywords:
Cc: Branch:
Release Notes:

Fixed TypeError rendering error page with [trac] use_chunked_encoding = enabled.

API Changes:

Description

I get the following error while investigating #13038 with [trac] use_chunked_encoding = enabled.

Exception happened during processing of request from ('192.168.11.29', 50776)
Traceback (most recent call last):
  File "/usr/lib/python2.7/SocketServer.py", line 596, in process_request_thread
    self.finish_request(request, client_address)
  File "/usr/lib/python2.7/SocketServer.py", line 331, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "/usr/lib/python2.7/SocketServer.py", line 652, in __init__
    self.handle()
  File "/usr/lib/python2.7/BaseHTTPServer.py", line 340, in handle
    self.handle_one_request()
  File "/home/jun66j5/src/tracdev/git/trac/web/wsgi.py", line 212, in handle_one_request
    gateway.run(self.server.application)
  File "/home/jun66j5/src/tracdev/git/trac/web/wsgi.py", line 112, in run
    response = application(self.environ, self._start_response)
  File "trac/web/standalone.py", line 63, in __call__
    return self.application(environ, start_response)
  File "trac/web/standalone.py", line 94, in __call__
    return self.application(environ, start_response)
  File "/home/jun66j5/src/tracdev/git/trac/web/main.py", line 632, in dispatch_request
    return _dispatch_request(req, env, env_error)
  File "/home/jun66j5/venv/py27/local/lib/python2.7/site-packages/memory_profiler.py", line 1072, in wrapper
    val = prof(func)(*args, **kwargs)
  File "/home/jun66j5/venv/py27/local/lib/python2.7/site-packages/memory_profiler.py", line 659, in f
    return func(*args, **kwds)
  File "/home/jun66j5/src/tracdev/git/trac/web/main.py", line 672, in _dispatch_request
    _send_user_error(req, env, e)
  File "/home/jun66j5/src/tracdev/git/trac/web/main.py", line 692, in _send_user_error
    req.send_error(sys.exc_info(), status=e.code, env=env, data=data)
  File "/home/jun66j5/src/tracdev/git/trac/web/api.py", line 842, in send_error
    self.send_header('Content-Length', len(out))
TypeError: object of type 'generator' has no len()

We should ignore [trac] use_chunked_encoding option when rendering the error (untested patch).

  • trac/web/api.py

    diff --git a/trac/web/api.py b/trac/web/api.py
    index 40fbf1493..02a1e22a2 100644
    a b class Request(object):  
    813813                if env:
    814814                    from trac.web.chrome import Chrome, add_stylesheet
    815815                    add_stylesheet(self, 'common/css/code.css')
    816                     metadata = {'content_type': 'text/html'}
     816                    metadata = {'content_type': 'text/html',
     817                                'iterable': False}
    817818                    try:
    818819                        out = Chrome(env).render_template(self, template, data,
    819820                                                          metadata)

Attachments (0)

Change History (7)

comment:1 by Ryan J Ollos, 15 months ago

Your patch resolves the issue per my testing. Alternatively, would the following be valid?:

  • trac/web/api.py

    diff --git a/trac/web/api.py b/trac/web/api.py
    index 40fbf1493..086c2cb81 100644
    a b class Request(object):  
    839839        self.send_header('Cache-Control', 'must-revalidate')
    840840        self.send_header('Expires', 'Fri, 01 Jan 1999 00:00:00 GMT')
    841841        self.send_header('Content-Type', content_type + ';charset=utf-8')
    842         self.send_header('Content-Length', len(out))
     842        if isinstance(out, basestring):
     843            self.send_header('Content-Length', len(out))
    843844        self._send_configurable_headers()
    844845        self._send_cookie_headers()

Though I suppose the error page doesn't need to be rendered in chunks because it's a fairly small amount of content.

I did some refactoring in rjollos.git:t13039_refactoring.

comment:2 by Ryan J Ollos, 15 months ago

Release Notes: modified (diff)

in reply to:  1 comment:3 by Jun Omae, 15 months ago

Replying to Ryan J Ollos:

I did some refactoring in rjollos.git:t13039_refactoring.

Looks good to me.

comment:4 by Ryan J Ollos, 15 months ago

I did some refactoring in r16637, but didn't run all the tests. I didn't consider that modifying the Request class would persist outside the scope of the module. Fixed in r16638.

comment:5 by Ryan J Ollos, 15 months ago

After this ticket is concluded I'll propose some related changes in #13042.

comment:6 by Ryan J Ollos, 15 months ago

Owner: set to Ryan J Ollos
Status: newassigned

comment:7 by Ryan J Ollos, 15 months ago

Resolution: fixed
Status: assignedclosed

Committed to trunk in r16656.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.