From fc03d0dfab64945169e1114cdc1fb39519a1e0c1 Mon Sep 17 00:00:00 2001 From: David Lord Date: Thu, 23 Feb 2023 09:29:36 -0800 Subject: [PATCH] setup method on registered blueprint is error --- CHANGES.rst | 2 ++ src/flask/blueprints.py | 19 ++++++------------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 032cdb94..a50bc18d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -20,6 +20,8 @@ Unreleased - ``json_encoder`` and ``json_decoder`` attributes on app and blueprint, and the corresponding ``json.JSONEncoder`` and ``JSONDecoder`` classes, are removed. - The ``json.htmlsafe_dumps`` and ``htmlsafe_dump`` functions are removed. + - Calling setup methods on blueprints after registration is an error instead of a + warning. :pr:`4997` - Importing ``escape`` and ``Markup`` from ``flask`` is deprecated. Import them directly from ``markupsafe`` instead. :pr:`4996` diff --git a/src/flask/blueprints.py b/src/flask/blueprints.py index 51f72279..eb50585d 100644 --- a/src/flask/blueprints.py +++ b/src/flask/blueprints.py @@ -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