#33882: Allow transaction.atomic to work in async contexts.
-------------------------------------+-------------------------------------
     Reporter:  alex                 |                    Owner:
                                     |  rajdesai24
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  4.0
  (models, ORM)                      |
     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 André S. Hansen):

 I am hesitant going for async django until transaction support is added or
 a cleaner solution than having to use **sync_to_async** is available. The
 problem with this workaround is that it forces you to write all code
 inside the transaction sync. Which is going to be a mess when transaction
 and non-transaction scopes want to use the same code/logic.

 Imagine the following simple example that illustrate the mess one will get
 in.

 {{{
 async def post():
     await sync_to_async(_post_sync_transaction)


 @transaction.atomic
 def _post_sync_transaction():
    logic1()
    async_to_sync(alogic2) # <-- Messy maintaining
    async_to_sync(alogic3) # <-- Messy maintaining


 async def get():
    await alogic2()
    await alogic3()


 def logic1():
    # ...


 async def alogic2():
    #...


 async def alogic3():
    # ...
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/33882#comment:18>
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/01070191af0e5de9-8f1d423d-7b33-4500-b838-9093079fca06-000000%40eu-central-1.amazonses.com.

Reply via email to