only open session if request hasn't been pushed yet

closes #1348
This commit is contained in:
David Lord 2017-06-02 11:10:18 -07:00
parent 5978a0f55f
commit 6637e20174
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
2 changed files with 15 additions and 8 deletions

View file

@ -325,15 +325,18 @@ class RequestContext(object):
_request_ctx_stack.push(self)
# Open the session at the moment that the request context is
# available. This allows a custom open_session method to use the
# request context (e.g. code that access database information
# stored on `g` instead of the appcontext).
session_interface = self.app.session_interface
self.session = session_interface.open_session(self.app, self.request)
# Open the session at the moment that the request context is available.
# This allows a custom open_session method to use the request context.
# Only open a new session if this is the first time the request was
# pushed, otherwise stream_with_context loses the session.
if self.session is None:
self.session = session_interface.make_null_session(self.app)
session_interface = self.app.session_interface
self.session = session_interface.open_session(
self.app, self.request
)
if self.session is None:
self.session = session_interface.make_null_session(self.app)
def pop(self, exc=_sentinel):
"""Pops the request context and unbinds it by doing that. This will