Opened 9 years ago

Closed 9 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 andrei kulakov)

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 andrei kulakov, 9 years ago

Description: modified (diff)

comment:2 by andrei kulakov, 9 years ago

Description: modified (diff)

comment:3 by andrei kulakov, 9 years ago

Description: modified (diff)

comment:4 by Carl Meyer, 9 years ago

Summary: admin.views.decorators.staff_member_required raises an exception when passed a valid argumentadmin.views.decorators.staff_member_required can't be used with decorator syntax and extra arguments
Triage Stage: UnreviewedAccepted

The issue here is simply that staff_member_required is not written to be automatically either a decorator or decorator-factory: it always requires a view_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.

comment:5 by Collin Anderson, 9 years ago

#24253 is about making staff_member_required a public api.

comment:6 by John Giannelos, 9 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.

Last edited 9 years ago by John Giannelos (previous) (diff)

comment:7 by Simon Charette, 9 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 Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: newclosed

In 08572e8d125da204fab230be5d1fdcc5d8d22256:

Fixed #24294 -- Allowed staff_member_required decorator to handle args.

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