Opened 16 years ago

Closed 16 years ago

Last modified 13 years ago

#9474 closed (fixed)

user_passes_test decorator cannot be applied twice

Reported by: Manuel Saelices Owned by: Manuel Saelices
Component: contrib.auth Version: 1.0
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Look at this code:

from django.contrib.auth.decorators import user_passes_test

def decorator1(view_func=None):
    def _test_func(user, *args, **kwargs):
        print 'decorator1 test func'
        return True
    return user_passes_test(_test_func)(view_func)

def decorator2(view_func=None):
    def _test_func(user, *args, **kwargs):
        print 'decorator2 test func'
        return True
    return user_passes_test(_test_func)(view_func)

@decorator1
@decorator2
def book_list(request):
    books = Book.objects.all()
    return render_to_response('books/book_list.html', {'books': books})

If you call book_list view, decorated both with decorator1 and decorator2, only decorator2 will be applied. For this exampled, only will appear in django console decorator2 test func.

This is for the use of update_wrapper function in _CheckLogin class in django/contrib/auth/decorators.py, that override __dict__ of function wrapped. Second decorator definition override self.view_func attribute of the other decorator (both are _CheckLogin objects).

Look at the patch for more details.

Attachments (1)

user_passes_test_decorator_r9295.diff (664 bytes ) - added by Manuel Saelices 16 years ago.
Patch that fixes issue

Download all attachments as: .zip

Change History (6)

by Manuel Saelices, 16 years ago

Patch that fixes issue

comment:1 by Jacob, 16 years ago

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:2 by Bob Thomas, 16 years ago

Has patch: set

comment:3 by Jacob, 16 years ago

Resolution: fixed
Status: newclosed

(In [10328]) Fixed #9474: user_passes_test may now be applied multiple times.

comment:4 by Jacob, 16 years ago

(In [10329]) [1.0.X] Fixed #9474: user_passes_test may now be applied multiple times. Backport of r10328 from trunk.

comment:5 by Jacob, 13 years ago

milestone: 1.1

Milestone 1.1 deleted

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