What's the alternative to create_scoped_session
in versions 3+ to create a session for the read replica?
#1375
-
Hey. There's a session created for read replica using |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can use the private attribute, with the understanding you're using something private that might change. Write tests so you catch if something does change in that case. Creating a bunch of scoped sessions is probably not doing what you intended it to. It requires you actually accessing the session again in a new scope in order to clean up the old scope. Flask-SQLAlchemy manages this by calling You might want to look at Flask-SQLAlchemy-Lite as an alternative if you want to manage the session yourself anyway: https://flask-sqlalchemy-lite.readthedocs.io/en/latest/session/ |
Beta Was this translation helpful? Give feedback.
You can use the private attribute, with the understanding you're using something private that might change. Write tests so you catch if something does change in that case.
Creating a bunch of scoped sessions is probably not doing what you intended it to. It requires you actually accessing the session again in a new scope in order to clean up the old scope. Flask-SQLAlchemy manages this by calling
session.remove()
at request teardown. So you probably just want to create instances offlask_sqlalchemy.session.Session(db)
instead.You might want to look at Flask-SQLAlchemy-Lite as an alternative if you want to manage the session yourself anyway: https://flask-sqlalchemy-lite.readthedocs.io/en…