You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Django Ninja supports both sync and async authentication classes, but even though sync authentication works well with both sync and async views; async authentication requires async views.
api = NinjaAPI(title="MyAPI", auth=MyAsyncTokenAuth())
this works well here:
async def my_async_view(request):
if request.auth["user"] == "foobar":
# The user is authenticated
but it fails with a sync view:
def my_async_view(request):
if request.auth["user"] == "foobar":
Exception:
builtins.TypeError: 'coroutine' object is not subscriptable
Cause
Although AsyncOperation._run_authentication checks if the __call__ method of the authentication class is async, its sync counterpart (Operation._run_authentication) does not perform this check.
Versions (please complete the following information):
Python version: [e.g. 3.11]
Django version: [e.g. 4.2.4]
Django-Ninja version: [e.g. 0.22.2]
Pydantic version: [e.g. 1.10.7]
The text was updated successfully, but these errors were encountered:
Describe the bug
Django Ninja supports both sync and async authentication classes, but even though sync authentication works well with both sync and async views; async authentication requires async views.
To reproduce:
then
this works well here:
but it fails with a sync view:
Exception:
Cause
Although
AsyncOperation._run_authentication
checks if the__call__
method of the authentication class is async, its sync counterpart (Operation._run_authentication
) does not perform this check.Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: