Skip to content
Myr

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.

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

authored by mvantellingen · committed by Armin Ronacher · parent da00160 · Browse files · 1 file+8 added−3 removed
This commit

State

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

Trailers

  • Signed-off-by: Armin Ronacher <armin.ronacher@active-4.com>

Diff stats

1 file+8 added−3 removed

  • other:+8 added−3 removed

1 file+8 added−3 removed

modified:flask/ctx.py+8 added-3 removed
28 unmodified lines
29 def __init__(self, app, environ):30 self.app = app31 self.request = app.request_class(environ)32 self.url_adapter = app.create_url_adapter(self.request)33 self.session = app.open_session(self.request)34 if self.session is None:35 self.session = _NullSession()33 self.g = _RequestGlobals()34 self.flashes = None35 self.session = None3637 try:38 url_rule, self.request.view_args = \39 self.url_adapter.match(return_rule=True)
4 unmodified lines
44 def push(self):45 """Binds the request context."""46 _request_ctx_stack.push(self)4748 # Open the session at the moment that the request context is49 # available. This allows a custom open_session method to use the50 # request context (e.g. flask-sqlalchemy).51 self.session = self.app.open_session(self.request)52 if self.session is None:53 self.session = _NullSession()5455 def pop(self):56 """Pops the request context."""57 _request_ctx_stack.pop()58
13 unmodified lines