mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
fix(dashboard): use datasource id from slice metadata (#12483)
This commit is contained in:
@@ -74,17 +74,15 @@ export function fetchAllSlices(userId) {
|
||||
const slices = {};
|
||||
json.result.forEach(slice => {
|
||||
let form_data = JSON.parse(slice.params);
|
||||
let { datasource } = form_data;
|
||||
if (!datasource) {
|
||||
datasource = getDatasourceParameter(
|
||||
slice.datasource_id,
|
||||
slice.datasource_type,
|
||||
);
|
||||
form_data = {
|
||||
...form_data,
|
||||
datasource,
|
||||
};
|
||||
}
|
||||
form_data = {
|
||||
...form_data,
|
||||
// force using datasource stored in relational table prop
|
||||
datasource:
|
||||
getDatasourceParameter(
|
||||
slice.datasource_id,
|
||||
slice.datasource_type,
|
||||
) || form_data.datasource,
|
||||
};
|
||||
slices[slice.id] = {
|
||||
slice_id: slice.id,
|
||||
slice_url: slice.url,
|
||||
@@ -93,6 +91,8 @@ export function fetchAllSlices(userId) {
|
||||
form_data,
|
||||
datasource_name: slice.datasource_name_text,
|
||||
datasource_url: slice.datasource_url,
|
||||
datasource_id: slice.datasource_id,
|
||||
datasource_type: slice.datasource_type,
|
||||
changed_on: new Date(slice.changed_on_utc).getTime(),
|
||||
description: slice.description,
|
||||
description_markdown: slice.description_markeddown,
|
||||
|
||||
@@ -25,6 +25,7 @@ from superset.charts.commands.importers.v1.utils import import_chart
|
||||
from superset.charts.dao import ChartDAO
|
||||
from superset.charts.schemas import ImportV1ChartSchema
|
||||
from superset.commands.importers.v1 import ImportModelsCommand
|
||||
from superset.connectors.sqla.models import SqlaTable
|
||||
from superset.databases.commands.importers.v1.utils import import_database
|
||||
from superset.databases.schemas import ImportV1DatabaseSchema
|
||||
from superset.datasets.commands.importers.v1.utils import import_dataset
|
||||
@@ -69,7 +70,7 @@ class ImportChartsCommand(ImportModelsCommand):
|
||||
database_ids[str(database.uuid)] = database.id
|
||||
|
||||
# import datasets with the correct parent ref
|
||||
dataset_info: Dict[str, Dict[str, Any]] = {}
|
||||
datasets: Dict[str, SqlaTable] = {}
|
||||
for file_name, config in configs.items():
|
||||
if (
|
||||
file_name.startswith("datasets/")
|
||||
@@ -77,18 +78,21 @@ class ImportChartsCommand(ImportModelsCommand):
|
||||
):
|
||||
config["database_id"] = database_ids[config["database_uuid"]]
|
||||
dataset = import_dataset(session, config, overwrite=False)
|
||||
dataset_info[str(dataset.uuid)] = {
|
||||
"datasource_id": dataset.id,
|
||||
"datasource_type": "view" if dataset.is_sqllab_view else "table",
|
||||
"datasource_name": dataset.table_name,
|
||||
}
|
||||
datasets[str(dataset.uuid)] = dataset
|
||||
|
||||
# import charts with the correct parent ref
|
||||
for file_name, config in configs.items():
|
||||
if (
|
||||
file_name.startswith("charts/")
|
||||
and config["dataset_uuid"] in dataset_info
|
||||
):
|
||||
if file_name.startswith("charts/") and config["dataset_uuid"] in datasets:
|
||||
# update datasource id, type, and name
|
||||
config.update(dataset_info[config["dataset_uuid"]])
|
||||
dataset = datasets[config["dataset_uuid"]]
|
||||
config.update(
|
||||
{
|
||||
"datasource_id": dataset.id,
|
||||
"datasource_type": "view"
|
||||
if dataset.is_sqllab_view
|
||||
else "table",
|
||||
"datasource_name": dataset.table_name,
|
||||
}
|
||||
)
|
||||
config["params"].update({"datasource": dataset.uid})
|
||||
import_chart(session, config, overwrite=overwrite)
|
||||
|
||||
@@ -140,10 +140,13 @@ class TestImportChartsCommand(SupersetTestCase):
|
||||
command = ImportChartsCommand(contents)
|
||||
command.run()
|
||||
|
||||
chart = db.session.query(Slice).filter_by(uuid=chart_config["uuid"]).one()
|
||||
chart: Slice = db.session.query(Slice).filter_by(
|
||||
uuid=chart_config["uuid"]
|
||||
).one()
|
||||
dataset = chart.datasource
|
||||
assert json.loads(chart.params) == {
|
||||
"color_picker": {"a": 1, "b": 135, "g": 122, "r": 0},
|
||||
"datasource": "12__table",
|
||||
"datasource": dataset.uid,
|
||||
"js_columns": ["color"],
|
||||
"js_data_mutator": "data => data.map(d => ({\\n ...d,\\n color: colors.hexToRGB(d.extraProps.color)\\n}));",
|
||||
"js_onclick_href": "",
|
||||
|
||||
Reference in New Issue
Block a user