Skip to content

What's the alternative to create_scoped_session in versions 3+ to create a session for the read replica? #1375

Discussion options

You must be logged in to vote

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 of flask_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…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by andrii-korotkov-verkada
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants