pallets/flask

When was 'Blueprint.before_app_first_request' deprecated and what replaces it?

ernstki opened this issue · 1 comments

I have resumed work on a Flask 1.x-based project after some time has passed, and sorting through deprecations and removals that have happened in the interim. The first place I got stuck was the @bp.before_app_first_request decorator.

Except to note that app.before_first_request and bp.before_app_first_request decorators are removed in 2.3.0, the changelog doesn't mention when these were deprecated, why, or what replaced them.

Perusing previous versions of the docs, I discover that Blueprint.before_app_first_request was deprecated in 2.2, with this note:

Deprecated since version 2.2: Will be removed in Flask 2.3. Run setup code when creating the application instead.

Something in my gut tells me that I'm going to be writing a kind of hook handler that will iterate through all the blueprints to run their "before first request" initialization routines. Effectively, an amateurish reimplementation of what Blueprint.before_app_first_request already did.

That leaves me wondering about the context for this deprecation. Can someone enlighten me as to why it was removed?

To be clear, I intend to document whatever workaround I come up with (for the benefit of others in this situation) and close this issue myself. I'm not asking for tech support or "homework help" from the Flask maintainers, or to resurrect the feature from the grave. :)

Duplicate of #5166

Use @bp.record_once to register a callback that is called the first time the blueprint is registered on an app, which would happen during your setup code.