From eda118964cd48e8bb4a18945c3bc30e28dfa0f09 Mon Sep 17 00:00:00 2001 From: laggardkernel Date: Fri, 28 May 2021 18:10:53 +0800 Subject: [PATCH] fix: get back _blueprint_order, important for template searching --- CHANGES.rst | 4 ++++ src/flask/app.py | 3 ++- src/flask/blueprints.py | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3e79b5cb..efc796e5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -8,6 +8,10 @@ Unreleased - Fix type annotation for ``teardown_request``. :issue:`4093` - Fix type annotation for ``before_request`` and ``before_app_request`` decorators. :issue:`4104` +- Re-add the ``Flask._blueprint_order`` list. Take blueprint registration + order into consideration when searching for templates in + ``DispatchingJinjaLoader._iter_loaders()``, + ``DispatchingJinjaLoader.list_templates()``. Version 2.0.1 diff --git a/src/flask/app.py b/src/flask/app.py index cacb40a5..0092f49b 100644 --- a/src/flask/app.py +++ b/src/flask/app.py @@ -463,6 +463,7 @@ class Flask(Scaffold): #: #: .. versionadded:: 0.7 self.blueprints: t.Dict[str, "Blueprint"] = {} + self._blueprint_order: t.List[Blueprint] = [] #: a place where extensions can store application specific state. For #: example this is where an extension could store database engines and @@ -1035,7 +1036,7 @@ class Flask(Scaffold): .. versionadded:: 0.11 """ - return self.blueprints.values() + return iter(self._blueprint_order) @setupmethod def add_url_rule( diff --git a/src/flask/blueprints.py b/src/flask/blueprints.py index 883fc2ff..fc109ec6 100644 --- a/src/flask/blueprints.py +++ b/src/flask/blueprints.py @@ -319,6 +319,8 @@ class Blueprint(Scaffold): ) app.blueprints[name] = self + if self not in app._blueprint_order: + app._blueprint_order.append(self) self._got_registered_once = True state = self.make_setup_state(app, options, first_registration)