Issuing multiple rollbacks to my python sqlite session ,causes my docker container to crash? How to avoid this crash?

44 views Asked by At

I am using this docker container to run my flask web app, FROM python:3.8.16. In my flask app, I have a code in a @after_request function where I rollback my sqlite session whenever any rest API returns a 500 response code.The frontend sometimes requests more than one rest API parallelly and if they both send a 500 response , the container simple crashes because I am issuing multiple rollbacks. how to avoid this container crash.

Session is created using sessionmaker of sqlite3

from sqlalchemy.orm import sessionmaker
session = sessionmaker(self.db)

After request containing session rollbacks

@app.after_request
def end_request(response):
    if response.status_code not in [200,201,202]:
        session.rollback()
0

There are 0 answers