Skip to content
Myr

Merge pull request #4169 from Rohan-Salwan/dev

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

fix raising error during cli lazy loading

authored by David Lord · committed by GitHub · parents 66d9d4f, 2305b05 · Browse files · 3 files+29 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+29 added−8 removed

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

3 files+29 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+18 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
285 unmodified lines
310 app = obj.load_app()311 assert app.name == "testapp"312313314def test_lazy_load_error(monkeypatch):315 """When using lazy loading, the correct exception should be316 re-raised.317 """318319 class BadExc(Exception):320 pass321322 def bad_load():323 raise BadExc324325 lazy = DispatchingApp(bad_load, use_eager_loading=False)326327 with pytest.raises(BadExc):328 lazy._flush_bg_loading_exception()329330331def test_with_appcontext(runner):332 @click.command()333 @with_appcontext334 def testcmd():
345 unmodified lines
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