Revert "[caching] Using request context rather than globals" (#9969)
This reverts commit 90cd3889ac02c7ccf1cc64e0458f6f337de246f8. Co-authored-by: John Bodley <john.bodley@airbnb.com>
This commit is contained in:
parent
15f267d586
commit
1001c6d5f4
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue