No frasco, isso deve fazer o truque: @app.teardown_appcontext def teardown_db(exception): db.session.commit() db.session.close()