Opened 10 years ago
Closed 10 years ago
#24294 closed Bug (fixed)
admin.views.decorators.staff_member_required can't be used with decorator syntax and extra arguments
Reported by: | andrei kulakov | Owned by: | andrei kulakov |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | yes | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description (last modified by )
When a valid argument is given to staff_member_required decorator, it raises this confusing error:
staff_member_required() takes at least 1 argument (1 given)
@staff_member_required(redirect_field_name='test') def v1(request): return HttpResponse("hi")
Change History (8)
comment:1 by , 10 years ago
Description: | modified (diff) |
---|
comment:2 by , 10 years ago
Description: | modified (diff) |
---|
comment:3 by , 10 years ago
Description: | modified (diff) |
---|
comment:4 by , 10 years ago
Summary: | admin.views.decorators.staff_member_required raises an exception when passed a valid argument → admin.views.decorators.staff_member_required can't be used with decorator syntax and extra arguments |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:6 by , 10 years ago
I pushed a branch with a fix for that ticket here:
https://github.com/johngian/django/tree/ticket_24294
Apparently there was already a pull request for that, sorry for the confusion.
comment:7 by , 10 years ago
Has patch: | set |
---|---|
Needs tests: | set |
Can you point to the existing pull request?
This will also require a test.
comment:8 by , 10 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
The issue here is simply that
staff_member_required
is not written to be automatically either a decorator or decorator-factory: it always requires aview_func
as its first positional argument. So it simply doesn't support the way you are trying to use it; if you want to provide extra options to it, you can no longer use it with@
syntax.If we are documenting it and making it public API, it should probably work like
login_required
, which would make your code work.