Merge pull request #4461 from pallets/cli-lazy-context

lazy loading preserves click context
This commit is contained in:
David Lord 2022-02-22 19:13:29 -08:00 committed by GitHub
commit 4843590c4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 0 deletions

View file

@ -42,6 +42,9 @@ Unreleased
- Add an ``--exclude-patterns`` option to the ``flask run`` CLI
command to specify patterns that will be ignored by the reloader.
:issue:`4188`
- When using lazy loading (the default with the debugger), the Click
context from the ``flask run`` command remains available in the
loader thread. :issue:`4460`
Version 2.0.3

View file

@ -301,9 +301,17 @@ class DispatchingApp:
self._load_in_background()
def _load_in_background(self):
# Store the Click context and push it in the loader thread so
# script_info is still available.
ctx = click.get_current_context(silent=True)
def _load_app():
__traceback_hide__ = True # noqa: F841
with self._lock:
if ctx is not None:
click.globals.push_context(ctx)
try:
self._load_unlocked()
except Exception as e: