Opened 15 years ago

Closed 15 years ago

#12750 closed (invalid)

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

Reported by: Phoebe Bright 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: no UI/UX: no

Description (last modified by Alex Gaynor)

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
        else:
            co = view_func.func_code   <---- fails here


Traceback:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/core/servers/basehttp.py", 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/basehttp.py", 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/wsgi.py", line 245, in __call__
    response = middleware_method(request, response)
  File "/Users/phoebebr/Development/tinycomms/tinycomm/debug_middleware.py", 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

Change History (2)

comment:1 by Alex Gaynor, 15 years ago

Description: modified (diff)

Please use preview.

comment:2 by Luke Plant, 15 years ago

Resolution: invalid
Status: newclosed

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.

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