Thanks for pushing this work. It's very cool!
So... Andrew (Godwin)'s
current PR blocks out the async interface for QuerySet. For now, it's a light-weight wrapper around the existing sync code, using sync_to_async to hand-off the DB operations to a thread pool executor. (Flavio Curella contributed initial tests last week, so I've currently asked that Simon and Mariusz have a look so we can assemble a TODO list to get it in.)
In terms of your PR, swapping connections __seems__ troublesome. (Perhaps not but 😬.) Until (if ever) we can work async into the all the right places, I'd imagined we'd provide both (sync and async) interfaces for the code that needs it. So, for example, and just an initial thought, since you're coming from the bottom can we, to begin, add a sync interface to the cursor (execute() and aexecute() say, using async_to_sync) that would allow the schema editor (&co) to think it's still talking to a sync driver? 🤔
If you do want to swap connections (even if only to make progress now...):
- Using an on-disk DB, specifying TEST["NAME"] maybe allow you to use the existing backend to create the tests, and then the async alias after that. (Exactly the flow into setup_databases() needs some thought there, but hard-coding a value or two should be enough for a PoC… 🤔)
- Searching for "sqlite multiple connections to in-memory database" doesn't come up empty. ...
More generally, I'd imagine setting the backend up as a third-party package would be the way to go, to allow space to experiment. Tim Graham's work on the
CockroachDB backend has that run against the Django test suite, which is a good pattern I'd guess. Exactly where low-end driver work meets higher-end API like work, like Andrew's PR, I don't think we yet know.