Django with Uvicorn and using thread.local

Looking forward advice/guide on deployment with Uvicorn and async in mind - while using thread.local.
If this isn’t the right place to post, Im happy to move it.

We are preparing to deploy our Django micro service into a Kubernetes cluster. We start Django with Uvicorn, as we are preparing (but not doing so yet) to move our API calls to being async.

We are using Django ninja to handle our API, and in there we handle authentication, and authorisation, reading a JWT passed by the client.

During this step, once the user has been authorised, I set their user ID and organisation Id on the thread using thread.local - and essentially treat the request and thread as 1:1.
This is so I can use it later during ORM functions (like get filter query set) and setting the filter() to use the current thread’s user Id and organisation Id.

I say this as I would like to sanity check some things:

  1. If we were to deploy now but us Gunicorn with Uvicorn worker class, not update our API endpoints to async, the current code would work?
  2. If we were to deploy without Gunicorn and just use Uvicorn, update our endpoints to async, our code would break as async and thread.local don’t play well together - if at all ?

I hope the scenario I’m explaining, and question, makes sense.
Thanks for any thoughts or pointers.

Correct. The whole purpose of async is to reduce the number of threads being used. The design intent of an async environment is that all views run in the same thread.