You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2021/01/13 16:50:25 UTC
[superset] branch master updated: fix(dashboard): use datasource id
from slice metadata (#12483)
This is an automated email from the ASF dual-hosted git repository.
villebro pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new f8270b0 fix(dashboard): use datasource id from slice metadata (#12483)
f8270b0 is described below
commit f8270b0b80c51d32a23661d104416b6b5df395d5
Author: Jesse Yang <je...@airbnb.com>
AuthorDate: Wed Jan 13 08:49:51 2021 -0800
fix(dashboard): use datasource id from slice metadata (#12483)
---
.../src/dashboard/actions/sliceEntities.js | 22 +++++++++---------
superset/charts/commands/importers/v1/__init__.py | 26 +++++++++++++---------
tests/charts/commands_tests.py | 7 ++++--
3 files changed, 31 insertions(+), 24 deletions(-)
diff --git a/superset-frontend/src/dashboard/actions/sliceEntities.js b/superset-frontend/src/dashboard/actions/sliceEntities.js
index 69472d9..2a344cb 100644
--- a/superset-frontend/src/dashboard/actions/sliceEntities.js
+++ b/superset-frontend/src/dashboard/actions/sliceEntities.js
@@ -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,
diff --git a/superset/charts/commands/importers/v1/__init__.py b/superset/charts/commands/importers/v1/__init__.py
index 4b3f443..0e2b5b3 100644
--- a/superset/charts/commands/importers/v1/__init__.py
+++ b/superset/charts/commands/importers/v1/__init__.py
@@ -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)
diff --git a/tests/charts/commands_tests.py b/tests/charts/commands_tests.py
index d1e862e..73c01ea 100644
--- a/tests/charts/commands_tests.py
+++ b/tests/charts/commands_tests.py
@@ -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": "",