Skip to content
Myr

Merge pull request #4997 from pallets/deprecate-got_first_request

Before adoption: this commit came in with the history the project adopted, so no landing records it.

deprecate `got_first_request`

authored by David Lord · committed by GitHub · parents 704b689, fc03d0d · Browse files · 4 files+19 added−16 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+19 added−16 removed

  • tests:+0 added−1 removed
  • other:+19 added−15 removed

4 files+19 added−16 removed

modified:src/flask/app.py+10 added-2 removed
6 unmodified lines
7import weakref8from collections.abc import Iterator as _abc_Iterator9from datetime import timedelta10from itertools import chain11from threading import Lock11from types import TracebackType1213import click14from werkzeug.datastructures import Headers
479 unmodified lines
494495 # tracks internally if the application already handled at least one496 # request.497 self._got_first_request = False499 self._before_request_lock = Lock()498499 # Add a static route using the provided static_url_path, static_host,500 # and static_folder if there is a configured static_folder.501 # Note we do this without checking if static_folder exists.
87 unmodified lines
589 def got_first_request(self) -> bool:590 """This attribute is set to ``True`` if the application started591 handling the first request.592593 .. deprecated:: 2.3594 Will be removed in Flask 2.4.595596 .. versionadded:: 0.8597 """598 import warnings599600 warnings.warn(601 "'got_first_request' is deprecated and will be removed in Flask 2.4.",602 DeprecationWarning,603 stacklevel=2,604 )605 return self._got_first_request606607 def make_config(self, instance_relative: bool = False) -> Config:608 """Used to create the config attribute by the Flask constructor.
1619 unmodified lines
modified:src/flask/blueprints.py+6 added-13 removed
205 unmodified lines
206 self._blueprints: t.List[t.Tuple["Blueprint", dict]] = []207208 def _check_setup_finished(self, f_name: str) -> None:209 if self._got_registered_once:210 import warnings211212 warnings.warn(213 f"The setup method '{f_name}' can no longer be called on"214 f" the blueprint '{self.name}'. It has already been"215 " registered at least once, any changes will not be"216 " applied consistently.\n"217 "Make sure all imports, decorators, functions, etc."218 " needed to set up the blueprint are done before"219 " registering it.\n"220 "This warning will become an exception in Flask 2.3.",221 UserWarning,222 stacklevel=3,210 raise AssertionError(211 f"The setup method '{f_name}' can no longer be called on the blueprint"212 f" '{self.name}'. It has already been registered at least once, any"213 " changes will not be applied consistently.\n"214 "Make sure all imports, decorators, functions, etc. needed to set up"215 " the blueprint are done before registering it."216 )217218 @setupmethod219 def record(self, func: t.Callable) -> None:
402 unmodified lines
modified:tests/test_basic.py-1 removed
1655 unmodified lines
1656 @app.route("/")1657 def index():1658 return "Awesome"16591660 assert not app.got_first_request1660 assert client.get("/").data == b"Awesome"16611662 with pytest.raises(AssertionError) as exc_info:1663 app.add_url_rule("/foo", endpoint="late")
256 unmodified lines
modified:CHANGES.rst+3 added
18 unmodified lines
19 are removed.20 - ``json_encoder`` and ``json_decoder`` attributes on app and blueprint, and the21 corresponding ``json.JSONEncoder`` and ``JSONDecoder`` classes, are removed.22 - The ``json.htmlsafe_dumps`` and ``htmlsafe_dump`` functions are removed.23 - Calling setup methods on blueprints after registration is an error instead of a24 warning. :pr:`4997`2526- Importing ``escape`` and ``Markup`` from ``flask`` is deprecated. Import them27 directly from ``markupsafe`` instead. :pr:`4996`28- The ``app.got_first_request`` property is deprecated. :pr:`4997`29- Use modern packaging metadata with ``pyproject.toml`` instead of ``setup.cfg``.30 :pr:`4947`31- Ensure subdomains are applied with nested blueprints. :issue:`4834`32
1418 unmodified lines