From 6e0ff2babb8d39b9e3cfc08ce93d43fc9fcb229f Mon Sep 17 00:00:00 2001 From: Kenny Kwan Date: Mon, 10 Apr 2023 15:40:03 -0700 Subject: [PATCH] fix url_params cache miss with global async query by setting global form_data import flask g fix linting fix linting 2 --- superset/charts/data/api.py | 5 ++++- superset/views/core.py | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/superset/charts/data/api.py b/superset/charts/data/api.py index 8e58440c76299..e48696219a9a9 100644 --- a/superset/charts/data/api.py +++ b/superset/charts/data/api.py @@ -21,7 +21,7 @@ from typing import Any, Dict, Optional, TYPE_CHECKING, Union import simplejson -from flask import current_app, make_response, request, Response +from flask import current_app, g, make_response, request, Response from flask_appbuilder.api import expose, protect from flask_babel import gettext as _ from marshmallow import ValidationError @@ -299,6 +299,9 @@ def data_from_cache(self, cache_key: str) -> Response: """ try: cached_data = self._load_query_context_form_from_cache(cache_key) + # Set form_data in Flask Global as it is used as a fallback + # for async queries with jinja context + setattr(g, "form_data", cached_data) query_context = self._create_query_context_from_form(cached_data) command = ChartDataCommand(query_context) command.validate() diff --git a/superset/views/core.py b/superset/views/core.py index 1d9d80c5b187a..72e1627331635 100755 --- a/superset/views/core.py +++ b/superset/views/core.py @@ -583,7 +583,9 @@ def explore_json_data(self, cache_key: str) -> FlaskResponse: form_data = cached.get("form_data") response_type = cached.get("response_type") - + # Set form_data in Flask Global as it is used as a fallback + # for async queries with jinja context + setattr(g, "form_data", form_data) datasource_id, datasource_type = get_datasource_info(None, None, form_data) viz_obj = get_viz(