-
-
Notifications
You must be signed in to change notification settings - Fork 16.7k
Description
Flask's before_first_request is being deprecated, due to some fairly valid reasoning. I totally get the reasoning behind it, and I even agree with it!
However, I have a Flask-based publishing framework that relies on its behavior. In particular, my framework wraps Flask via inheritance. This framework makes use of another library which needs to be able to access app.secret_key at the time of its own instantiation, and also call app.add_url_rule before the first request is handled. In effect, this code happens in my framework's __init__:
class ExtendedApp(flask.Flask):
def __init__(self, name, cfg, **kwargs):
super().__init__(name, cfg, **kwargs)
self.before_first_request(self._setup_other_library)
def _setup_other_library(self):
self._library_instance = OtherLibrary(self)and then to keep things simple, my framework's setup looks like:
app = ExtendedApp(...)
app.secret_key = 'sd89u7f9sduf9sd'Since OtherLibrary's constructor needs to be able to obtain the already-set app.secret_key as part of its setup, and needs to be able to add_url_rule on the Flask application before the first request is served, this setup can't happen conditionally in the first request's before_request handler, and I'd rather not have to add another method to ExtendedApp like finish_setup() or the like.
Also, I had originally not used inheritance (instead providing a library function that generated and configured a Flask application), but for some reason this ended up not being workable for other reasons (I forget what, precisely, but I suspect it had to do with the startup behavior of the ORM I'm using).
So, my feature request is to bring back before_first_request, possibly renaming it to give it a better sense of "please don't use this if you don't have to."
Thanks.