deprecate before_first_request

This commit is contained in:
David Lord 2022-06-06 10:00:21 -07:00
parent 7a2d5fb6df
commit 96c97dec09
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
6 changed files with 66 additions and 33 deletions

View file

@ -543,7 +543,20 @@ class Blueprint(Scaffold):
) -> ft.BeforeFirstRequestCallable:
"""Like :meth:`Flask.before_first_request`. Such a function is
executed before the first request to the application.
.. deprecated:: 2.2
Will be removed in Flask 2.3. Run setup code when creating
the application instead.
"""
import warnings
warnings.warn(
"'before_app_first_request' is deprecated and will be"
" removed in Flask 2.3. Use 'record_once' instead to run"
" setup code when registering the blueprint.",
DeprecationWarning,
stacklevel=2,
)
self.record_once(lambda s: s.app.before_first_request_funcs.append(f))
return f