This is an automated email from the ASF dual-hosted git repository.

johnbodley pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 1001c6d  Revert "[caching] Using request context rather than globals" 
(#9969)
1001c6d is described below

commit 1001c6d5f482f4950ef45317efab87ad203dd7d4
Author: John Bodley <4567245+john-bod...@users.noreply.github.com>
AuthorDate: Tue Jun 2 16:03:33 2020 -0700

    Revert "[caching] Using request context rather than globals" (#9969)
    
    This reverts commit 90cd3889ac02c7ccf1cc64e0458f6f337de246f8.
    
    Co-authored-by: John Bodley <john.bod...@airbnb.com>
---
 superset/views/core.py  | 10 +++-------
 superset/views/utils.py |  6 +++++-
 tests/utils_tests.py    | 16 ++++++++++++++++
 3 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/superset/views/core.py b/superset/views/core.py
index 6c7e2b2..3d89334 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -1745,13 +1745,9 @@ class Superset(BaseSupersetView):
                     force=True,
                 )
 
-                # Temporarily define the form-data in the request context 
which may be
-                # leveraged by the Jinja macros.
-                with app.test_request_context(
-                    data={"form_data": json.dumps(form_data)}
-                ):
-                    payload = obj.get_payload()
-
+                g.form_data = form_data
+                payload = obj.get_payload()
+                delattr(g, "form_data")
                 error = payload["errors"] or None
                 status = payload["status"]
             except Exception as ex:
diff --git a/superset/views/utils.py b/superset/views/utils.py
index 3b5fd3a..5ed7e48 100644
--- a/superset/views/utils.py
+++ b/superset/views/utils.py
@@ -20,7 +20,7 @@ from typing import Any, Dict, List, Optional, Tuple
 from urllib import parse
 
 import simplejson as json
-from flask import request
+from flask import g, request
 
 import superset.models.core as models
 from superset import app, db, is_feature_enabled
@@ -111,6 +111,10 @@ def get_form_data(
     if request_args_data:
         form_data.update(json.loads(request_args_data))
 
+    # Fallback to using the Flask globals (used for cache warmup) if defined.
+    if not form_data and hasattr(g, "form_data"):
+        form_data = getattr(g, "form_data")
+
     url_id = request.args.get("r")
     if url_id:
         saved_url = db.session.query(models.Url).filter_by(id=url_id).first()
diff --git a/tests/utils_tests.py b/tests/utils_tests.py
index 02d4a88..709d111 100644
--- a/tests/utils_tests.py
+++ b/tests/utils_tests.py
@@ -1300,3 +1300,19 @@ class UtilsTestCase(SupersetTestCase):
             )
 
             self.assertEqual(slc, None)
+
+    def test_get_form_data_globals(self) -> None:
+        with app.test_request_context():
+            g.form_data = {"foo": "bar"}
+            form_data, slc = get_form_data()
+            delattr(g, "form_data")
+
+            self.assertEqual(
+                form_data,
+                {
+                    "foo": "bar",
+                    "time_range_endpoints": 
get_time_range_endpoints(form_data={}),
+                },
+            )
+
+            self.assertEqual(slc, None)

Reply via email to