Where's the request scoping? #1077
-
I've been told all up and down the internet over the years that one of the beauties of flask-sqlalchemy over the generic version is that it handles niceties like automatically scoping sessions to requests (even better than scoping to threads). But from reading the code all I can find is an attempt to scope to threads. I'm sure I missed something but does the code somewhere swap in a more specific scope_func, or are we just working on the assumption that thread scope will get us the same effect. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
You don't have multiple requests in parallel in the same thread so yes, I think you assumption is correct. |
Beta Was this translation helpful? Give feedback.
-
The session is scoped to the Flask application context in Flask-SQLAlchemy 3. Because an active context is required, the session will always be cleaned up after it is used. The context is unique to each thread/greenlet/coroutine because it uses |
Beta Was this translation helpful? Give feedback.
The session is scoped to the Flask application context in Flask-SQLAlchemy 3. Because an active context is required, the session will always be cleaned up after it is used. The context is unique to each thread/greenlet/coroutine because it uses
contextvars
.