I wrote ✏️ πŸŽ‰ an article about Running Tasks Concurrently in Django Asynchronous Views  Buckle-up for our async-journey together! πŸš— #django #python #async

https://fly.io/blog/running-tasks-concurrently-in-django-asynchronous-views/

Running tasks concurrently in Django asynchronous views

Django is been getting more and more async abilities! Mariusz Felisiak explores how to run multiple async tasks in a Django asynchronous views.

Fly
@felixxm Thanks for the article! I believe there shouldn't be a "not" in this sentence, though: "This is how we have to do it until async connections are not supported in the Django ORM […]" :)
@felixxm Reading further: wouldn't "f'SELECT EXISTS(SELECT 1 FROM {user_db_table} WHERE "email" = %s', [email]" be more appropriate for the raw SQL replacing an aexists() call?
@olepbr This example is not about getting exactly the same but about getting the same functionality. I wanted to use the simplest and shortest statement possible.
@felixxm interesting article. πŸ‘
Instead of "... perform a raw SQL statement" it would be better to create the query and extract SQL and params like this: πŸ‘‡
```
query = get_user_model().objects.filter(email=email)
sql, params = qs.query.exists().sql_with_params()
cursor.execute(sql, params)
```
@paulox @felixxm It would be interesting to see what a minimal Django-like take on β€œGive me an async connection, and execute this query” would look like. πŸ€”

@carlton @paulox @felixxm now you're into something I was just pondering...
How django-sql-explorer might utilise async πŸ‘€πŸ˜¬

But I've still not written any async Django so it's still just thoughts as I read these posts.

@paulox As a responsible maintainer πŸ˜‡ I didn't want to recommend any undocumented hooks πŸ€«πŸ˜‰
@felixxm you're totally right. Let's document it πŸ™‚
https://code.djangoproject.com/ticket/34636
#34636 (Add documentation for Query's function `sql_with_params`) – Django

@paulox TBH, I'm far from making it an official APIπŸ”₯ We don't want to encourage using raw SQL quieres 🀷
@felixxm @paulox While I agree that that it can be useful it feels more like fixing the symptoms than the cause. Documenting it makes it part of the API contract, do we want that? I'd very much would think no.
@apollo13 @felixxm you both convinced me. But what's the issue to have a fully asynchronous database operation at least with Psycopg 3.1+ ?
@paulox @felixxm I am not sure what you mean with this question. I don't see a problem with psycopg's async support.

@apollo13 @felixxm I actually worded the sentence very badly. πŸ˜…

Mariusz showed in his article how you can make a fully asynchronous database query by manually creating an asynchronous connection and raw SQL statements. πŸ‘‡
https://fly.io/django-beats/running-tasks-concurrently-in-django-asynchronous-views/#using-the-orm

It would be useful to make this possible directly in Django, at least when using PostgreSQL and Psycopg 3.1+ but I couldn't find an issue about it in the tracker, and I don't know if it doesn't exist or I couldn't find it. 🀷

Running tasks concurrently in Django asynchronous views

Django is been getting more and more async abilities! Mariusz Felisiak explores how to run multiple async tasks in a Django asynchronous views.

Fly
@paulox @felixxm probably doesn't exist. It is also not clear what the API would look like?