#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)
Change History (6)
by , 16 years ago
Attachment: | user_passes_test_decorator_r9295.diff added |
---|
comment:1 by , 16 years ago
milestone: | → 1.1 |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 16 years ago
Has patch: | set |
---|
comment:3 by , 16 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:4 by , 16 years ago
Note:
See TracTickets
for help on using tickets.
Patch that fixes issue