Cannot stack login_required and staff_member_required decorators
ryancausey opened this issue · 2 comments
ryancausey commented
When trying to use code like the following:
@query.field("accounts")
@login_required
@staff_member_required
def resolve_accounts(*_):
return Account.objects.all()
It results in a stack trace like the following:
IndexError: tuple index out of range
File "graphql/execution/execute.py", line 617, in resolve_field
result = resolve_fn(source, info, **args)
File "ariadne_jwt/decorators.py", line 27, in wrapper
info = args[f.__code__.co_varnames.index('info')]
GraphQLError: tuple index out of range
GraphQL request:2:3
1 | {
2 | accounts {
| ^
3 | name
File "graphql/execution/execute.py", line 617, in resolve_field
result = resolve_fn(source, info, **args)
File "ariadne_jwt/decorators.py", line 27, in wrapper
info = args[f.__code__.co_varnames.index('info')]
I've traced it to the context
decorator that is used inside the user_passes_test
decorator. I do not know what info = args[f.__code__.co_varnames.index('info')]
accomplishes, but there is no "info" value in the co_varnames
of staff_member_required
which causes the exception.
ryancausey commented
It actually looks like the way the context
decorator is designed, it requires the resolver to have the right positional argument name in the right place. A resolver that uses def resolve_accounts(*_)
can't be decorated and resolve successfully.
ryancausey commented
I can confirm this is resolved with #17.