Skip to content
Myr

Merge pull request #3794 from mbpreble/open-session-request-endpoint-none

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

Ensure session_interface.open_session is called after URL matching

authored by David Lord · committed by GitHub · parents 15f0fc2, 0162148 · Browse files · 3 files+28 added−3 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+28 added−3 removed

  • tests:+22 added−0 removed
  • other:+6 added−3 removed

3 files+28 added−3 removed

modified:src/flask/ctx.py+3 added-3 removed
359 unmodified lines
360 self._implicit_app_ctx_stack.append(None)361362 _request_ctx_stack.push(self)363364 if self.url_adapter is not None:365 self.match_request()366367 # Open the session at the moment that the request context is available.368 # This allows a custom open_session method to use the request context.369 # Only open a new session if this is the first time the request was370 # pushed, otherwise stream_with_context loses the session.
3 unmodified lines
374375 if self.session is None:376 self.session = session_interface.make_null_session(self.app)377375 if self.url_adapter is not None:376 self.match_request()377378 def pop(self, exc=_sentinel):379 """Pops the request context and unbinds it by doing that. This will380 also trigger the execution of functions registered by the381 :meth:`~flask.Flask.teardown_request` decorator.
61 unmodified lines
added:tests/test_session_interface.py+22 added
1import flask2from flask.sessions import SessionInterface345def test_open_session_endpoint_not_none():6 # Define a session interface that breaks if request.endpoint is None7 class MySessionInterface(SessionInterface):8 def save_session(self):9 pass1011 def open_session(self, _, request):12 assert request.endpoint is not None1314 def index():15 return "Hello World!"1617 # Confirm a 200 response, indicating that request.endpoint was NOT None18 app = flask.Flask(__name__)19 app.route("/")(index)20 app.session_interface = MySessionInterface()21 response = app.test_client().open("/")22 assert response.status_code == 200
modified:CHANGES.rst+3 added
58 unmodified lines
59 not set, otherwise ``public``. This tells browsers to validate60 conditional requests instead of using a timed cache. :pr:`3828`61- ``helpers.safe_join`` is deprecated. Use62 ``werkzeug.utils.safe_join`` instead. :pr:`3828`63- The request context does route matching before opening the session.64 This could allow a session interface to change behavior based on65 ``request.endpoint``. :issue:`3776`666768Version 1.1.269-------------
1011 unmodified lines