@ -30,11 +30,9 @@ class _RequestContext(object):
self . app = app
self . app = app
self . request = app . request_class ( environ )
self . request = app . request_class ( environ )
self . url_adapter = app . create_url_adapter ( self . request )
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 . g = _RequestGlobals ( )
self . flashes = None
self . flashes = None
self . session = None
try :
try :
url_rule , self . request . view_args = \
url_rule , self . request . view_args = \
@ -47,6 +45,13 @@ class _RequestContext(object):
""" Binds the request context. """
""" Binds the request context. """
_request_ctx_stack . push ( self )
_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 ) :
def pop ( self ) :
""" Pops the request context. """
""" Pops the request context. """
_request_ctx_stack . pop ( )
_request_ctx_stack . pop ( )