From 25f71751aa7386651c90d1f274bb68798773d97a Mon Sep 17 00:00:00 2001 From: Sergey Motornyuk Date: Wed, 28 Aug 2019 13:36:12 +0300 Subject: [PATCH] Initialize JinjaOptions right after app creation. Starting from Flask>=1.0, some of plain `app` properties were rewritten as property descriptors, so setting them may accidentialy initialize JinjaEnvironment. After this point jinja2 won't notice any change to `jinja_options`. So I reordered assignment in app initialization and now `jinja_options` added firstly. --- ckan/config/middleware/flask_app.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ckan/config/middleware/flask_app.py b/ckan/config/middleware/flask_app.py index fa0d4d670df..d5b1ec69c4d 100644 --- a/ckan/config/middleware/flask_app.py +++ b/ckan/config/middleware/flask_app.py @@ -82,6 +82,15 @@ def make_flask_stack(conf, **app_conf): debug = asbool(conf.get('debug', conf.get('DEBUG', False))) testing = asbool(app_conf.get('testing', app_conf.get('TESTING', False))) app = flask_app = CKANFlask(__name__) + # Set jinja_options as soon as possible as it won't affect + # tempaltes in any way after JinjaEnvironment created. It may be + # not obvious, but some of `app` properties are implemented as + # property descriptors, so even assigning can implicitly create + # JinjaEnvironment. + # + # https://flask.palletsprojects.com/en/1.1.x/api/#flask.Flask.jinja_options + app.jinja_options = jinja_extensions.get_jinja_env_options() + app.debug = debug app.testing = testing app.template_folder = os.path.join(root, 'templates')