wait until app ctx is ready before matching url

`RequestContext.match_request` is moved from `__init__` to `push`. This
causes matching to happen later, when the app context is available.
This enables URL converters that use things such as the database.
This commit is contained in:
Elad Moshe 2019-02-24 23:54:57 +02:00 committed by David Lord
parent 29111a3259
commit 1ff98a2d21
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
4 changed files with 41 additions and 24 deletions

View file

@ -314,9 +314,6 @@ class RequestContext(object):
# functions.
self._after_request_functions = []
if self.url_adapter is not None:
self.match_request()
@property
def g(self):
return _app_ctx_stack.top.g
@ -384,6 +381,9 @@ class RequestContext(object):
_request_ctx_stack.push(self)
if self.url_adapter is not None:
self.match_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