Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[caching] Using request context rather than globals #9715

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 7 additions & 3 deletions superset/views/core.py
Expand Up @@ -1715,9 +1715,13 @@ def warm_up_cache(self):
force=True,
)

g.form_data = form_data
payload = obj.get_payload()
delattr(g, "form_data")
# 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()

error = payload["error"]
status = payload["status"]
except Exception as ex:
Expand Down
6 changes: 1 addition & 5 deletions superset/views/utils.py
Expand Up @@ -20,7 +20,7 @@
from urllib import parse

import simplejson as json
from flask import g, request
from flask import request

import superset.models.core as models
from superset import app, db, is_feature_enabled
Expand Down Expand Up @@ -111,10 +111,6 @@ 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()
Expand Down
16 changes: 0 additions & 16 deletions tests/utils_tests.py
Expand Up @@ -1312,19 +1312,3 @@ def test_get_form_data_request_args_and_form(self) -> None:
)

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)