Skip to content

Commit

Permalink
teardown_request support for flask-sqlalchemy
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jun 24, 2011
1 parent 421a1c2 commit 8d28185
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion flaskext/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,15 @@ def init_app(self, app):
app.extensions = {}
app.extensions['sqlalchemy'] = _SQLAlchemyState(self, app)

@app.after_request
# 0.7 introduced the new `teardown_request` decorator which has better
# semantics than the after_request one. We should use it if
# available.
if hasattr(app, 'teardown_request'):
teardown = app.teardown_request
else:
teardown = app.after_request

@teardown
def shutdown_session(response):
self.session.remove()
return response
Expand Down

0 comments on commit 8d28185

Please sign in to comment.