python - How to make Flask-SQLAlchemy automatically rollback the session if an exception is raised? -


i'd setup app built flask-sqlalchemy rollback changes done database if view raises exception bubbles outside view code (i.e. not catched inside).

i'd work if objects flushed database in subtransactions, either automatically or directly via session.commit().

something similar django's transaction request wrapping.

you can this:

@app.teardown_request def teardown_request(exception):     if exception:         db.session.rollback()     db.session.remove() 

have here teardown_request info. might need set preserve_context_on_exception config variable if in debug mode.


Comments

Popular posts from this blog

html - Difficulties with background-image property -

visual studio code - What does the isShellCommand property actually do and how should you use it? -

ios - Segue not passing data between ViewControllers -