File tree Expand file tree Collapse file tree 4 files changed +40
-0
lines changed Expand file tree Collapse file tree 4 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ Version 0.10.2
24
24
- Raise an :exc:`AttributeError` in :func:`flask.helpers.find_package` with a
25
25
useful message explaining why it is raised when a PEP 302 import hook is used
26
26
without an `is_package()` method.
27
+ - Fixed an issue causing exceptions raised before entering a request or app
28
+ context to be passed to teardown handlers.
27
29
28
30
Version 0.10.1
29
31
--------------
Original file line number Diff line number Diff line change @@ -163,6 +163,8 @@ def __init__(self, app):
163
163
def push (self ):
164
164
"""Binds the app context to the current context."""
165
165
self ._refcnt += 1
166
+ if hasattr (sys , 'exc_clear' ):
167
+ sys .exc_clear ()
166
168
_app_ctx_stack .push (self )
167
169
appcontext_pushed .send (self .app )
168
170
@@ -312,6 +314,9 @@ def push(self):
312
314
else :
313
315
self ._implicit_app_ctx_stack .append (None )
314
316
317
+ if hasattr (sys , 'exc_clear' ):
318
+ sys .exc_clear ()
319
+
315
320
_request_ctx_stack .push (self )
316
321
317
322
# Open the session at the moment that the request context is
Original file line number Diff line number Diff line change @@ -63,6 +63,23 @@ def cleanup(exception):
63
63
64
64
self .assert_equal (cleanup_stuff , [None ])
65
65
66
+ def test_app_tearing_down_with_previous_exception (self ):
67
+ cleanup_stuff = []
68
+ app = flask .Flask (__name__ )
69
+ @app .teardown_appcontext
70
+ def cleanup (exception ):
71
+ cleanup_stuff .append (exception )
72
+
73
+ try :
74
+ raise Exception ('dummy' )
75
+ except Exception :
76
+ pass
77
+
78
+ with app .app_context ():
79
+ pass
80
+
81
+ self .assert_equal (cleanup_stuff , [None ])
82
+
66
83
def test_custom_app_ctx_globals_class (self ):
67
84
class CustomRequestGlobals (object ):
68
85
def __init__ (self ):
Original file line number Diff line number Diff line change @@ -33,6 +33,22 @@ def end_of_request(exception):
33
33
ctx .pop ()
34
34
self .assert_equal (buffer , [None ])
35
35
36
+ def test_teardown_with_previous_exception (self ):
37
+ buffer = []
38
+ app = flask .Flask (__name__ )
39
+ @app .teardown_request
40
+ def end_of_request (exception ):
41
+ buffer .append (exception )
42
+
43
+ try :
44
+ raise Exception ('dummy' )
45
+ except Exception :
46
+ pass
47
+
48
+ with app .test_request_context ():
49
+ self .assert_equal (buffer , [])
50
+ self .assert_equal (buffer , [None ])
51
+
36
52
def test_proper_test_request_context (self ):
37
53
app = flask .Flask (__name__ )
38
54
app .config .update (
You can’t perform that action at this time.
0 commit comments