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
Provenance
- Commit
c690f52- Tree
65edd45- Author
David Lord <davidism@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
704b689- Parent 2
fc03d0d
4 files changed+19 added−16 removed
modified:src/flask/app.py+10 added-2 removed
6 unmodified lines7 import weakref8 from collections.abc import Iterator as _abc_Iterator9 from datetime import timedelta10 from itertools import chain11-from threading import Lock11 from types import TracebackType12 13 import click14 from werkzeug.datastructures import Headers479 unmodified lines494 495 # tracks internally if the application already handled at least one496 # request.497 self._got_first_request = False499- self._before_request_lock = Lock()498 499 # 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 lines589 def got_first_request(self) -> bool:590 """This attribute is set to ``True`` if the application started591 handling the first request.592 593+ .. deprecated:: 2.3594+ Will be removed in Flask 2.4.595+596 .. versionadded:: 0.8597 """598+ import warnings599+600+ 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_request606 607 def make_config(self, instance_relative: bool = False) -> Config:608 """Used to create the config attribute by the Flask constructor.1619 unmodified linesmodified:src/flask/blueprints.py+6 added-13 removed
205 unmodified lines206 self._blueprints: t.List[t.Tuple["Blueprint", dict]] = []207 208 def _check_setup_finished(self, f_name: str) -> None:209 if self._got_registered_once:210- import warnings211-212- 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 )217 218 @setupmethod219 def record(self, func: t.Callable) -> None:402 unmodified linesmodified:tests/test_basic.py-1 removed
1655 unmodified lines1656 @app.route("/")1657 def index():1658 return "Awesome"1659 1660- assert not app.got_first_request1660 assert client.get("/").data == b"Awesome"1661 1662 with pytest.raises(AssertionError) as exc_info:1663 app.add_url_rule("/foo", endpoint="late")256 unmodified linesmodified:CHANGES.rst+3 added
18 unmodified lines19 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`25 26 - 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