mirror of
https://github.com/apache/superset.git
synced 2026-04-07 10:31:50 +00:00
fix: update table ID in query context on chart import (#16374)
* fix: update table ID in query context on chart import * Fix test
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
from typing import Any, Dict, Set
|
||||
|
||||
from marshmallow import Schema
|
||||
@@ -95,4 +96,10 @@ class ImportChartsCommand(ImportModelsCommand):
|
||||
}
|
||||
)
|
||||
config["params"].update({"datasource": dataset.uid})
|
||||
if config["query_context"]:
|
||||
# TODO (betodealmeida): export query_context as object, not string
|
||||
query_context = json.loads(config["query_context"])
|
||||
query_context["datasource"] = {"id": dataset.id, "type": "table"}
|
||||
config["query_context"] = json.dumps(query_context)
|
||||
|
||||
import_chart(session, config, overwrite=overwrite)
|
||||
|
||||
@@ -191,6 +191,34 @@ class TestImportChartsCommand(SupersetTestCase):
|
||||
)
|
||||
assert dataset.table_name == "imported_dataset"
|
||||
assert chart.table == dataset
|
||||
assert json.loads(chart.query_context) == {
|
||||
"datasource": {"id": dataset.id, "type": "table"},
|
||||
"force": False,
|
||||
"queries": [
|
||||
{
|
||||
"time_range": " : ",
|
||||
"filters": [],
|
||||
"extras": {
|
||||
"time_grain_sqla": None,
|
||||
"having": "",
|
||||
"having_druid": [],
|
||||
"where": "",
|
||||
},
|
||||
"applied_time_extras": {},
|
||||
"columns": [],
|
||||
"metrics": [],
|
||||
"annotation_layers": [],
|
||||
"row_limit": 5000,
|
||||
"timeseries_limit": 0,
|
||||
"order_desc": True,
|
||||
"url_params": {},
|
||||
"custom_params": {},
|
||||
"custom_form_data": {},
|
||||
}
|
||||
],
|
||||
"result_format": "json",
|
||||
"result_type": "full",
|
||||
}
|
||||
|
||||
database = (
|
||||
db.session.query(Database).filter_by(uuid=database_config["uuid"]).one()
|
||||
|
||||
@@ -444,6 +444,7 @@ chart_config: Dict[str, Any] = {
|
||||
},
|
||||
"viz_type": "deck_path",
|
||||
},
|
||||
"query_context": '{"datasource":{"id":12,"type":"table"},"force":false,"queries":[{"time_range":" : ","filters":[],"extras":{"time_grain_sqla":null,"having":"","having_druid":[],"where":""},"applied_time_extras":{},"columns":[],"metrics":[],"annotation_layers":[],"row_limit":5000,"timeseries_limit":0,"order_desc":true,"url_params":{},"custom_params":{},"custom_form_data":{}}],"result_format":"json","result_type":"full"}',
|
||||
"cache_timeout": None,
|
||||
"uuid": "0c23747a-6528-4629-97bf-e4b78d3b9df1",
|
||||
"version": "1.0.0",
|
||||
|
||||
Reference in New Issue
Block a user