#36872: Django's template engine cannot handle asynchronous methods
---------------------------------+--------------------------------------
     Reporter:  Ricardo Robles   |                    Owner:  (none)
         Type:  Bug              |                   Status:  new
    Component:  Template system  |                  Version:  6.0
     Severity:  Normal           |               Resolution:
     Keywords:  Template, Async  |             Triage Stage:  Unreviewed
    Has patch:  0                |      Needs documentation:  0
  Needs tests:  0                |  Patch needs improvement:  0
Easy pickings:  0                |                    UI/UX:  1
---------------------------------+--------------------------------------
Comment (by Ricardo Robles):

 Replying to [comment:1 Zachary W]:
 > Could be related. There is an **async_to_sync** function in **asgiref**:
 
https://github.com/django/asgiref/blob/2b28409ab83b3e4cf6fed9019403b71f8d7d1c51/asgiref/sync.py#L585

 You're correct, the most elegant and simple way to do it would be:
 {{{
     def resolve(self, context, ignore_failures=False):
         if self.is_var:
             try:
                 obj = self.var.resolve(context)
                 if asyncio.iscoroutine(obj):
                     obj = async_to_sync(lambda: obj)()
                 ...

 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/36872#comment:2>
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 visit 
https://groups.google.com/d/msgid/django-updates/0107019be09968f1-d690bd84-ac54-4d9f-b774-faa6b15f0b33-000000%40eu-central-1.amazonses.com.

Reply via email to