#31920: ASGI/ASYNC SessionMiddleware - SynchronousOnlyOperation exception if
request.user is not unwrapped in sync code
----------------------------------+------------------------------------
Reporter: Michael Galler | Owner: lirontb
Type: New feature | Status: assigned
Component: contrib.sessions | Version: 3.1
Severity: Normal | Resolution:
Keywords: async | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------+------------------------------------
Comment (by Andrew Godwin):
Chatted with lirontb about this at the DCUS2022 sprints, and we believe we
can just implement the `__await__` method on SimpleLazyObject, roughly
like this:
{{{
class X:
def __await__(self):
if isinstance(self.wrapped, coroutine):
async def inner():
result = await coroutine
self.wrapped = result
return result
return inner().__await__()
else:
async def result():
return self.wrapped
return result().__await__()
}}}
That would mean we could simply `await request.user` (or any other
SimpleLazyObject) and get the value out. If this works, we could even
consider this for the related object descriptors for foreign keys...!
--
Ticket URL: <https://code.djangoproject.com/ticket/31920#comment:10>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/01070183f67f60a8-d29e3dc3-5396-46cd-9647-f5559957ac89-000000%40eu-central-1.amazonses.com.