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
Accessing the view will raise: django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
This is because accessing request.user involves DB query (when using Django's default session engine) and can only be run in sync context. But in AsyncOperation._run_authentication() it didn't switch the context for the authentication callback.
Versions (please complete the following information):
Python version: 3.12
Django version: 5.0.7
Django-Ninja version: 1.2.2
Pydantic version: 2.8.2
The text was updated successfully, but these errors were encountered:
Describe the bug
If an authentication callback can only works in sync context, then it will not work on async views.
Example Code:
Accessing the view will raise:
django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - use a thread or sync_to_async.
This is because accessing
request.user
involves DB query (when using Django's default session engine) and can only be run in sync context. But inAsyncOperation._run_authentication()
it didn't switch the context for the authentication callback.Versions (please complete the following information):
The text was updated successfully, but these errors were encountered: