ATOMIC_REQUESTS and async views
See original GitHub issueFirst of all, thank you very much for your work on this project. I sincerely hope that you and your family are doing well and I sincerely pray for the resolution of the conflict in Ukraine.
Describe the bug I’m getting a RuntimeError on my django ninja async views when ATOMIC_REQUESTS is true
Versions
- Python version: 3.10
- Django version: 4.0.3
- Django-Ninja version: 0.17.0
# settings.py
DATABASES["default"]["ATOMIC_REQUESTS"] = True
# api.py
@transaction.non_atomic_requests
@router.post("/flight-hotel-search", response=FlightHotelSearchResult)
async def flight_hotel_search(request:HttpRequest, criteria: FlightHotelSearchCriteria):
# there is zero database call done by me in this view
...
# Error
# RuntimeError: You cannot use ATOMIC_REQUESTS with async views.
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
Asynchronous support — Django 4.1.4 documentation
Django has support for writing asynchronous (“async”) views, along with an entirely async-enabled request stack if you are running under ASGI. Async views...
Read more >Django 3.1 can't manage to run views asynchronously
Under a WSGI server, async views will run in their own, one-off event loop. is also applied to ASGI mode. Here's the code...
Read more >Is it possible to use transaction.atomic with async functions?
I'm trying to use select_for_update in an async application. It requires a transaction to work, but I can't find a way to use ......
Read more >Fixing your Django async job - database integration - /var/
Another solution would be to set ATOMIC_REQUESTS to True and disable atomic requests for the specific view that starts the asynchronous job ...
Read more >Async Views in Django - TestDriven.io
This tutorial looks at how to get started with Django's asynchronous views.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ah that makes sense, yeah its one of the big gotchas of async and Django, until the ORM is finished its rough to get it all playing together.
yes, they were suppose to be async http call to external services. The atomic requests is on the entire project. I have this setting on by default on all of my projects. I plan to use async code in only one view anyway, it doesn’t make sense to me to disable atomic requests for the sole purpose of making one specific view work