lazy loading preserves click context

This commit is contained in:
David Lord 2022-02-22 19:04:03 -08:00
parent 3897a51801
commit aa13521d42
No known key found for this signature in database
GPG Key ID: 7A1C87E3F5BC42A8
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: