Skip to content

Commit

Permalink
fix: update table ID in query context on chart import (apache#16374)
Browse files Browse the repository at this point in the history
* fix: update table ID in query context on chart import

* Fix test
  • Loading branch information
betodealmeida authored and Emmanuel Bavoux committed Nov 14, 2021
1 parent ce725e0 commit dc96e9f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
7 changes: 7 additions & 0 deletions superset/charts/commands/importers/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -95,4 +96,10 @@ def _import(
}
)
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)
28 changes: 28 additions & 0 deletions tests/integration_tests/charts/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,34 @@ def test_import_v1_chart(self):
)
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()
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/fixtures/importexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@
},
"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",
Expand Down

0 comments on commit dc96e9f

Please sign in to comment.