forked from orbit-oss/flask
Open the session after the request context is pushed on the stack instead of in the constructor. This allows you to access the request context in a custom open_session method.
Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>
This commit is contained in:
parent
da00160db6
commit
b3fc9eb36b
1 changed files with 8 additions and 3 deletions
11
flask/ctx.py
11
flask/ctx.py
|
|
@ -30,11 +30,9 @@ class _RequestContext(object):
|
|||
self.app = app
|
||||
self.request = app.request_class(environ)
|
||||
self.url_adapter = app.create_url_adapter(self.request)
|
||||
self.session = app.open_session(self.request)
|
||||
if self.session is None:
|
||||
self.session = _NullSession()
|
||||
self.g = _RequestGlobals()
|
||||
self.flashes = None
|
||||
self.session = None
|
||||
|
||||
try:
|
||||
url_rule, self.request.view_args = \
|
||||
|
|
@ -47,6 +45,13 @@ class _RequestContext(object):
|
|||
"""Binds the request context."""
|
||||
_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. flask-sqlalchemy).
|
||||
self.session = self.app.open_session(self.request)
|
||||
if self.session is None:
|
||||
self.session = _NullSession()
|
||||
|
||||
def pop(self):
|
||||
"""Pops the request context."""
|
||||
_request_ctx_stack.pop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue