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
Post a Comment