Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix @before_first_request rasing exception #940

Closed
wants to merge 2 commits into from

2 participants

Tim-Erwin Armin Ronacher
Tim-Erwin

I tried using @before_first_request but ran into an AssertionError in @setupmethod because before actually executing the functions app._got_first_request was set to True indicating it's already too late. So I just moved it after the execution of the functions. Also I made the decorator leave the functions intact so they could be used directly.

Tim Mundt added some commits
Armin Ronacher
Owner

Do you have a test of how you triggered this? A @setupmethod should never be a @before_first_request method.

Armin Ronacher mitsuhiko closed this
Tim-Erwin

Within the @before_first_request method I'm calling a function that is a @setupmethod. Also a "do not"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 2, 2014
  1. set app._got_first_request to True only after executing 'before_first…

    Tim Mundt authored
    …_request_funcs' to prevent AssertionError in @setupmethod
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 1 deletion.
  1. +2 −1  flask/app.py
3  flask/app.py
View
@@ -1204,6 +1204,7 @@ def before_first_request(self, f):
.. versionadded:: 0.8
"""
self.before_first_request_funcs.append(f)
+ return f
@setupmethod
def after_request(self, f):
@@ -1490,9 +1491,9 @@ def try_trigger_before_first_request_functions(self):
with self._before_request_lock:
if self._got_first_request:
return
- self._got_first_request = True
for func in self.before_first_request_funcs:
func()
+ self._got_first_request = True
def make_default_options_response(self):
"""This method is called to create the default `OPTIONS` response.
Something went wrong with that request. Please try again.