Comments (6)
allauth currently does not support async, see #3546. Likely, this needs to be applied to the middleware:
https://docs.djangoproject.com/en/4.2/topics/http/middleware/#asynchronous-support
Can you check if that fixes the issue? A PR is welcome.
from django-allauth.
I have a fix for this in the pipeline...
from django-allauth.
This could work I think:
from asgiref.sync import iscoroutinefunction, markcoroutinefunction
from asgiref import sync
from allauth.core import context
from allauth.account import middleware
class AccountMiddleware(middleware.AccountMiddleware):
async_capable = True
sync_capable = True
def __init__(self, get_response):
self.get_response = get_response
if iscoroutinefunction(self.get_response):
markcoroutinefunction(self)
def __call__(self, request):
if iscoroutinefunction(self):
return self.__acall__(request)
return super().__call__(request)
async def __acall__(self, request):
with context.request_context(request):
response = await self.get_response(request)
await sync.sync_to_async(self._remove_dangling_login)(request, response)
return response
I did it using inheritance but the classes would have to be merged.
from django-allauth.
Doesn't sync_to_async
spawn a thread to run the sync code? In any case, I have avoided that here #3568 -- also not very pretty, doubling code, but it's what Django recommends.
from django-allauth.
You are right, it is not required.
from django-allauth.
Updated:
from asgiref.sync import iscoroutinefunction, markcoroutinefunction
from allauth.core import context
from allauth.account import middleware
class AccountMiddleware(middleware.AccountMiddleware):
async_capable = True
sync_capable = True
def __init__(self, get_response):
self.get_response = get_response
if iscoroutinefunction(self.get_response):
markcoroutinefunction(self)
def __call__(self, request):
if iscoroutinefunction(self):
return self.__acall__(request)
return super().__call__(request)
async def __acall__(self, request):
with context.request_context(request):
response = await self.get_response(request)
self._remove_dangling_login(request, response)
return response
from django-allauth.
Related Issues (20)
- AttributeError: 'UserSignUpForm' object has no attribute 'try_save' HOT 1
- Assertion Error for Existing Users After Registering New User with Social Account HOT 2
- LOGIN_ON_EMAIL_CONFIRMATION does not work for users created manually eg. via admin HOT 1
- Google Social Login Error - ImmatureSignatureError: The token is not yet valid (iat)
- [tox] Can't find msgfmt HOT 2
- ModuleNotFoundError: No module named 'user' HOT 2
- 2FA Setup - QR Code/Secret Key Invalidation on Incorrect Token Entry HOT 3
- login_required CBV consistency HOT 1
- Signing up new users, facing username duplicate errors (0.61.1) HOT 10
- Regular accounts only HOT 1
- Get id_token for send to the URL logout keycloak
- Initial value for the SignUpForm
- what is `by_id()` replaced with? HOT 1
- Wrong 'da' translation of "Password Reset Email" /locale/da/LC_MESSAGES /django.po HOT 1
- Microsoft provider does not have extract_email_addresses function defined HOT 1
- TikTok provider needed HOT 5
- keep getting error retrieving access token for microsoft oauth and using 0.61.1 HOT 3
- About old version Document. HOT 1
- Password reset from key (email) issue - invalid link - solved HOT 2
- typo in `authentication_required` in headless RESTView HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-allauth.