Replies: 1 comment
-
This is a question about Flask-SQLAlchemy, not Flask, please ask it in the appropriate place. Note that the answer will be along the lines of "you can't set binds that way". Flask-SQLAlchemy has it's own way to manage binds, so you need to override the |
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
-
We have an environment with the following libraries and versions;
Normally, we run on a single RDS Mysql but because of the high load we needed to add a read replica and we have following configurations;
Before creating the read replica we would use db and session like;
After creating the read replica we have added a read_session like;
and started use it like;
read_session.query(MyEntity).filter_by(id=self.id).all()
but after this point, our application started to produce errors like
Packet sequence number wrong - got x but expected y
andCan't reconnect until invalid transaction is rolled back
.When I googled the error, I see that the reason of this error is multi-threading and it says every request should be handled in separate sessions but I wonder how it would work before creating the read replica. It seems Flask-SQLAlchemy uses the same session for all request because session is created with same way we did in Flasck-SQLAlchemy instance. Related code in Flask-SQLAlchemy =>
I wonder, what we did wrong and how we can create a session to use every where like Flask-SQLAlchemy did it?
Beta Was this translation helpful? Give feedback.
All reactions