Can I safely use contextvar with django?

Hello,
I need to store the request object globally, so non-view function can reference it without explicity passing it as a parameter.

I tried to write middleware that store the request object in contextvar, However, I would like to ask about the safety of this approach?

In general, an extremely bad idea.

Pass the request as a parameter.

1 Like