Is the connection request context maintained for other requests? #1752
-
According to the implementation notes in the documentation, Flask-SocketIO allows access to the request context, and this request context is shared for all events that occur over the course of a single connection. I have some code like so:
Does the context not extend to the connection event? Or am I misunderstanding how socketio handles the request context? Or something else? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
You are asking about the request context, but in the code you are modifying the request object and expecting it to be preserved. That's not how it works, the request object is not preserved, each event handler gets its own request object. If you want to store some data for a client you should write it to the user session. |
Beta Was this translation helpful? Give feedback.
-
Thanks for the (really, incredibly) fast reply, and for the clarification on the object/context. I'm still a bit fuzzy on this distinction -- just to be sure I fully understand, I can do something like:
or do I have to do something else to write to the user session? |
Beta Was this translation helpful? Give feedback.
You are asking about the request context, but in the code you are modifying the request object and expecting it to be preserved. That's not how it works, the request object is not preserved, each event handler gets its own request object. If you want to store some data for a client you should write it to the user session.