Skip to content
Myr

Merge pull request #2354 from davidism/stream-session

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

Only open session if request does not have open session

authored by David Lord · committed by GitHub · parents 49f3e96, 6637e20 · Browse files · 3 files+29 added−8 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−8 removed

  • tests:+14 added−0 removed
  • other:+15 added−8 removed

3 files+29 added−8 removed

modified:flask/ctx.py+11 added-8 removed
323 unmodified lines
324 sys.exc_clear()325326 _request_ctx_stack.push(self)327328 # Open the session at the moment that the request context is329 # available. This allows a custom open_session method to use the330 # request context (e.g. code that access database information331 # stored on `g` instead of the appcontext).332 session_interface = self.app.session_interface333 self.session = session_interface.open_session(self.app, self.request)334328 # Open the session at the moment that the request context is available.329 # This allows a custom open_session method to use the request context.330 # Only open a new session if this is the first time the request was331 # pushed, otherwise stream_with_context loses the session.332 if self.session is None:336 self.session = session_interface.make_null_session(self.app)333 session_interface = self.app.session_interface334 self.session = session_interface.open_session(335 self.app, self.request336 )337338 if self.session is None:339 self.session = session_interface.make_null_session(self.app)340341 def pop(self, exc=_sentinel):342 """Pops the request context and unbinds it by doing that. This will343 also trigger the execution of functions registered by the344 :meth:`~flask.Flask.teardown_request` decorator.
71 unmodified lines
modified:tests/test_helpers.py+14 added
859 unmodified lines
860 rv = client.get('/?name=World')861 assert rv.data == b'Hello World!'862 assert called == [42]863864 def test_stream_keeps_session(self, app, client):865 @app.route('/')866 def index():867 flask.session['test'] = 'flask'868869 @flask.stream_with_context870 def gen():871 yield flask.session['test']872873 return flask.Response(gen())874875 rv = client.get('/')876 assert rv.data == b'flask'877878879class TestSafeJoin(object):880 def test_safe_join(self):881 # Valid combinations of *args and expected joined paths.882 passing = (
64 unmodified lines
modified:CHANGES+4 added
65 unmodified lines
66 ``BadRequestKeyError`` has a message with the bad key in debug mode instead67 of the generic bad request message. (`#2348`_)68- Allow registering new tags with ``TaggedJSONSerializer`` to support69 storing other types in the session cookie. (`#2352`_)70- Only open the session if the request has not been pushed onto the context71 stack yet. This allows ``stream_with_context`` generators to access the same72 session that the containing view uses. (`#2354`_)7374.. _#1489: https://github.com/pallets/flask/pull/148975.. _#1621: https://github.com/pallets/flask/pull/162176.. _#1898: https://github.com/pallets/flask/pull/1898
12 unmodified lines
89.. _#2319: https://github.com/pallets/flask/pull/231990.. _#2326: https://github.com/pallets/flask/pull/232691.. _#2348: https://github.com/pallets/flask/pull/234892.. _#2352: https://github.com/pallets/flask/pull/235293.. _#2354: https://github.com/pallets/flask/pull/23549495Version 0.12.296--------------97
617 unmodified lines