From 33f11ce9131aa6807b3dcba2927b985b3987b529 Mon Sep 17 00:00:00 2001 From: amercader Date: Thu, 17 Aug 2017 13:08:29 +0100 Subject: [PATCH] Push a test request context at the start of paster commands This is in order to avoid Flask RuntimeErrors when trying to generate URLs without a request context being present. --- ckan/lib/cli.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ckan/lib/cli.py b/ckan/lib/cli.py index 7040c8afbdd..2f6683e91a5 100644 --- a/ckan/lib/cli.py +++ b/ckan/lib/cli.py @@ -28,6 +28,7 @@ import ckan.include.rcssmin as rcssmin import ckan.plugins as p from ckan.common import config +from ckan.tests.helpers import _get_test_app #NB No CKAN imports are allowed until after the config file is loaded. @@ -224,6 +225,11 @@ def load_config(config, load_site_user=True): from ckan.config.environment import load_environment load_environment(conf.global_conf, conf.local_conf) + flask_app = _get_test_app().flask_app + flask_context = flask_app.test_request_context() + + flask_context.push() + registry = Registry() registry.prepare() import pylons