setup method on registered blueprint is error

This commit is contained in:
David Lord 2023-02-23 09:29:36 -08:00
parent 2a33c17854
commit fc03d0dfab
No known key found for this signature in database
GPG key ID: 7A1C87E3F5BC42A8
2 changed files with 8 additions and 13 deletions

View file

@ -207,19 +207,12 @@ class Blueprint(Scaffold):
def _check_setup_finished(self, f_name: str) -> None:
if self._got_registered_once:
import warnings
warnings.warn(
f"The setup method '{f_name}' can no longer be called on"
f" the blueprint '{self.name}'. It has already been"
" registered at least once, any changes will not be"
" applied consistently.\n"
"Make sure all imports, decorators, functions, etc."
" needed to set up the blueprint are done before"
" registering it.\n"
"This warning will become an exception in Flask 2.3.",
UserWarning,
stacklevel=3,
raise AssertionError(
f"The setup method '{f_name}' can no longer be called on the blueprint"
f" '{self.name}'. It has already been registered at least once, any"
" changes will not be applied consistently.\n"
"Make sure all imports, decorators, functions, etc. needed to set up"
" the blueprint are done before registering it."
)
@setupmethod