Skip to content
Myr

ensure error while opening session pops context

Before adoption: this commit came in with the history the project adopted, so no landing records it.

errors will be handled by the app error handlers closes #1538, closes #1528

authored by David Lord · committed by David Lord · parent f22da31 · Browse files · 3 files+29 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+29 added−1 removed

  • tests:+25 added−0 removed
  • other:+4 added−1 removed

3 files+29 added−1 removed

modified:flask/app.py+1 added-1 removed
2000 unmodified lines
2001 a list of headers and an optional2002 exception context to start the response2003 """2004 ctx = self.request_context(environ)2005 ctx.push()2005 error = None2006 try:2007 try:2008 ctx.push()2009 response = self.full_dispatch_request()2010 except Exception as e:2011 error = e2012 response = self.handle_exception(e)
18 unmodified lines
modified:tests/test_reqctx.py+25 added
10 unmodified lines
1112import pytest1314import flask15from flask.sessions import SessionInterface1617try:18 from greenlet import greenlet19except ImportError:
173 unmodified lines
193 assert rv.data == b'Hello World!'194195 result = greenlets[0].run()196 assert result == 42197198199def test_session_error_pops_context():200 class SessionError(Exception):201 pass202203 class FailingSessionInterface(SessionInterface):204 def open_session(self, app, request):205 raise SessionError()206207 class CustomFlask(flask.Flask):208 session_interface = FailingSessionInterface()209210 app = CustomFlask(__name__)211212 @app.route('/')213 def index():214 # shouldn't get here215 assert False216217 response = app.test_client().get('/')218 assert response.status_code == 500219 assert not flask.request220 assert not flask.current_app
modified:CHANGES+3 added
23 unmodified lines
24- Add support for ``provide_automatic_options`` in ``add_url_rule`` to disable25 adding OPTIONS method when the ``view_func`` argument is not a class.26 (`#1489`_).27- ``MethodView`` can inherit method handlers from base classes. (`#1936`_)28- Errors caused while opening the session at the beginning of the request are29 handled by the app's error handlers. (`#2254`_)3031.. _#1489: https://github.com/pallets/flask/pull/148932.. _#1936: https://github.com/pallets/flask/pull/193633.. _#2017: https://github.com/pallets/flask/pull/201734.. _#2223: https://github.com/pallets/flask/pull/222335.. _#2254: https://github.com/pallets/flask/pull/22543637Version 0.12.138--------------39
608 unmodified lines