Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ 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`
- The ``app.got_first_request`` property is deprecated. :pr:`4997`
- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.
:pr:`4947`
- Ensure subdomains are applied with nested blueprints. :issue:`4834`
Expand Down
12 changes: 10 additions & 2 deletions src/flask/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from collections.abc import Iterator as _abc_Iterator
from datetime import timedelta
from itertools import chain
from threading import Lock
from types import TracebackType

import click
Expand Down Expand Up @@ -496,7 +495,6 @@ def __init__(
# tracks internally if the application already handled at least one
# request.
self._got_first_request = False
self._before_request_lock = Lock()

# Add a static route using the provided static_url_path, static_host,
# and static_folder if there is a configured static_folder.
Expand Down Expand Up @@ -592,8 +590,18 @@ def got_first_request(self) -> bool:
"""This attribute is set to ``True`` if the application started
handling the first request.

.. deprecated:: 2.3
Will be removed in Flask 2.4.

.. versionadded:: 0.8
"""
import warnings

warnings.warn(
"'got_first_request' is deprecated and will be removed in Flask 2.4.",
DeprecationWarning,
stacklevel=2,
)
return self._got_first_request

def make_config(self, instance_relative: bool = False) -> Config:
Expand Down
19 changes: 6 additions & 13 deletions src/flask/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,19 +207,12 @@ def __init__(

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
Expand Down
1 change: 0 additions & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,7 +1657,6 @@ def test_no_setup_after_first_request(app, client):
def index():
return "Awesome"

assert not app.got_first_request
assert client.get("/").data == b"Awesome"

with pytest.raises(AssertionError) as exc_info:
Expand Down