Skip to content
Myr

correctly handle raising deferred errors in cli lazy loading

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

authored by Rohan salwan · committed by David Lord · parent 66d9d4f · Browse files · 3 files+16 added−8 removed
This commit

State

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

Diff stats

3 files+16 added−8 removed

  • tests:+5 added−0 removed
  • other:+11 added−8 removed

3 files+16 added−8 removed

modified:src/flask/cli.py+9 added-8 removed
310 unmodified lines
311 def __init__(self, loader, use_eager_loading=None):312 self.loader = loader313 self._app = None314 self._lock = Lock()315 self._bg_loading_exc_info = None315 self._bg_loading_exc = None316317 if use_eager_loading is None:318 use_eager_loading = os.environ.get("WERKZEUG_RUN_MAIN") != "true"319
7 unmodified lines
327 __traceback_hide__ = True # noqa: F841328 with self._lock:329 try:330 self._load_unlocked()331 except Exception:332 self._bg_loading_exc_info = sys.exc_info()331 except Exception as e:332 self._bg_loading_exc = e333334 t = Thread(target=_load_app, args=())335 t.start()336337 def _flush_bg_loading_exception(self):338 __traceback_hide__ = True # noqa: F841339 exc_info = self._bg_loading_exc_info340 if exc_info is not None:341 self._bg_loading_exc_info = None342 raise exc_info339 exc = self._bg_loading_exc340341 if exc is not None:342 self._bg_loading_exc = None343 raise exc344345 def _load_unlocked(self):346 __traceback_hide__ = True # noqa: F841347 self._app = rv = self.loader()347 self._bg_loading_exc_info = None348 self._bg_loading_exc = None349 return rv350351 def __call__(self, environ, start_response):352 __traceback_hide__ = True # noqa: F841
643 unmodified lines
modified:tests/test_cli.py+5 added
15 unmodified lines
16from flask import Blueprint17from flask import current_app18from flask import Flask19from flask.cli import AppGroup20from flask.cli import DispatchingApp21from flask.cli import dotenv22from flask.cli import find_best_app23from flask.cli import FlaskGroup24from flask.cli import get_version
634 unmodified lines
659 if int(click.__version__[0]) < 8:660 pytest.deprecated_call(cli_main, match=".* Click 7 is deprecated")661 else:662 cli_main()663664665def test_load_in_background():666 pytest.raises(Exception, DispatchingApp, "appname123")
modified:CHANGES.rst+2 added
15 unmodified lines
16- Fix the type of ``static_folder`` to accept ``pathlib.Path``.17 :issue:`4150`18- ``jsonify`` handles ``decimal.Decimal`` by encoding to ``str``.19 :issue:`4157`20- Correctly handle raising deferred errors in CLI lazy loading.21 :issue:`4096`222324Version 2.0.125-------------
1154 unmodified lines