Opened 4 years ago

Closed 4 years ago

#12750 closed (invalid)

Middleware snippet getting error in 1.2 alpha 1 - AttributeError: 'MethodDecoratorAdaptor' object has no attribute 'func_code

Reported by: phoebebright Owned by: nobody
Component: Uncategorized Version: 1.2-alpha
Severity: Keywords: middleware, decorator
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by Alex)

Section of code causing error:

       from django.core.urlresolvers import resolve
        view_func, args, kwargs = resolve(request.META['PATH_INFO'])

         if hasattr(view_func,'view_func'):
            # it the view_func has a view_func then its a decorator
            co = view_func.view_func.func_code
            co = view_func.func_code   <---- fails here

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/", line 280, in run
    self.result = application(self.environ, self.start_response)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/", line 672, in __call__
    return self.application(environ, start_response)
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/handlers/", line 245, in __call__
    response = middleware_method(request, response)
  File "/Users/phoebebr/Development/tinycomms/tinycomm/", line 117, in process_response
    co = view_func.func_code
AttributeError: 'MethodDecoratorAdaptor' object has no attribute 'func_code'
[01/Feb/2010 17:38:49] "GET /who/availability/ HTTP/1.1" 500 841

Attachments (0)

Change History (2)

comment:1 Changed 4 years ago by Alex

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Please use preview.

comment:2 Changed 4 years ago by lukeplant

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

Your code relied on the implementation of the user_passes_test decorator - in particular the _CheckLogin object, which is why it has broken, because that implementation has changed.

In your case, it looks like you are assuming that if the callable does not have an attribute 'view_func', then it is a function. That is an obviously false assumption.

Add Comment

Modify Ticket

Change Properties
<Author field>
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'

E-mail address and user name can be saved in the Preferences.

Note: See TracTickets for help on using tickets.