Skip to content

Commit

Permalink
Merge branch '0.10-maintenance'
Browse files Browse the repository at this point in the history
  • Loading branch information
DasIch committed Oct 16, 2013
2 parents 544118b + a3a2f52 commit b63a992
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -24,6 +24,8 @@ Version 0.10.2
- Raise an :exc:`AttributeError` in :func:`flask.helpers.find_package` with a
useful message explaining why it is raised when a PEP 302 import hook is used
without an `is_package()` method.
- Fixed an issue causing exceptions raised before entering a request or app
context to be passed to teardown handlers.

Version 0.10.1
--------------
Expand Down
5 changes: 5 additions & 0 deletions flask/ctx.py
Expand Up @@ -163,6 +163,8 @@ def __init__(self, app):
def push(self):
"""Binds the app context to the current context."""
self._refcnt += 1
if hasattr(sys, 'exc_clear'):
sys.exc_clear()
_app_ctx_stack.push(self)
appcontext_pushed.send(self.app)

Expand Down Expand Up @@ -312,6 +314,9 @@ def push(self):
else:
self._implicit_app_ctx_stack.append(None)

if hasattr(sys, 'exc_clear'):
sys.exc_clear()

_request_ctx_stack.push(self)

# Open the session at the moment that the request context is
Expand Down
17 changes: 17 additions & 0 deletions flask/testsuite/appctx.py
Expand Up @@ -63,6 +63,23 @@ def cleanup(exception):

self.assert_equal(cleanup_stuff, [None])

def test_app_tearing_down_with_previous_exception(self):
cleanup_stuff = []
app = flask.Flask(__name__)
@app.teardown_appcontext
def cleanup(exception):
cleanup_stuff.append(exception)

try:
raise Exception('dummy')
except Exception:
pass

with app.app_context():
pass

self.assert_equal(cleanup_stuff, [None])

def test_custom_app_ctx_globals_class(self):
class CustomRequestGlobals(object):
def __init__(self):
Expand Down
16 changes: 16 additions & 0 deletions flask/testsuite/reqctx.py
Expand Up @@ -33,6 +33,22 @@ def end_of_request(exception):
ctx.pop()
self.assert_equal(buffer, [None])

def test_teardown_with_previous_exception(self):
buffer = []
app = flask.Flask(__name__)
@app.teardown_request
def end_of_request(exception):
buffer.append(exception)

try:
raise Exception('dummy')
except Exception:
pass

with app.test_request_context():
self.assert_equal(buffer, [])
self.assert_equal(buffer, [None])

def test_proper_test_request_context(self):
app = flask.Flask(__name__)
app.config.update(
Expand Down

0 comments on commit b63a992

Please sign in to comment.