Replies: 1 comment
-
You're essentially asking "How bad is it to use global variables?" I'm not really sure what to say. That question kind of answers itself. The problems with global variables are well known. Use at your own risk. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
How bad would it be to save Middleware
scope
into a ContextVar?On the HTTP/sync side, we can use threadlocal storage (TLS) to make the current request & user accessible from anywhere. This approach unfortunately no longer works in the world of channels/websockets, so I'm looking for alternatives.
I know it would be better practice to plumb the
scope
through, but that would be a major change touching many functions throughout the codebase. And many of those fuctions are shared across sync and async.This use case seems like why we have ContextVar in the first place. But I'm not very confident making this change as I don't fully understand the inner workings of Django channels.
Beta Was this translation helpful? Give feedback.
All reactions