Closed jvdboog closed 7 months ago
I can confirm the issue. It occurs when the session has not been loaded yet, and the middleware is the first one to trigger the actual load. Possibly related:
https://code.djangoproject.com/ticket/34901
Trouble is, there is no way of triggering the load of a session asynchronously due to the ticket above, and using sync_to_async
in the middleware does not sound like a plan as the middleware always kicks in, meaning all views would be hampered by this.
TBD what to do.
Here -- https://github.com/django/django/pull/17372/files -- request.session.ahas_key()
is being introduced, which is what the middleware should be using. Looks like this issue is blocked on missing Django functionality.
Given that the Django pull request is using sync_to_async()
under the hood as well, see #3614
Can you give this a try @jvdboog ?
I have been seeing the same error. The https://github.com/pennersr/django-allauth/pull/3614 update fixed it. Thanks!
Merged.
@bkbirr @jvdboog I would appreciate it if you could comment over at https://github.com/pennersr/django-allauth/issues/3546 what, according to you, is missing / needs to be done in order to improve interop with async. If all is simply working as is for you, then that is also valuable information to hear.
Hello!
I get the following error when I upgraded django-allauth from 55.2 to 60.1.
After further investigation the cause of this is the following:
In the AccountMiddleware. Trying to access session is a (sync) database request. However, since I am running it from an async environment, Django throws an error. Trying to find a solution is hard, since I cannot remove AccountMiddleware, since Django won't start due to an Improperly configured error.
Is there anything I could do to solve this?
Thanks!