mirror of https://github.com/apache/superset.git
fix: apply template_params on external_metadata (#14996)
* fix: apply template_params on external_metadata * Fix test
This commit is contained in:
parent
c8cf4b6bbf
commit
8e7f0237ab
|
@ -638,7 +638,9 @@ class SqlaTable( # pylint: disable=too-many-public-methods,too-many-instance-at
|
||||||
db_engine_spec = self.db_engine_spec
|
db_engine_spec = self.db_engine_spec
|
||||||
if self.sql:
|
if self.sql:
|
||||||
engine = self.database.get_sqla_engine(schema=self.schema)
|
engine = self.database.get_sqla_engine(schema=self.schema)
|
||||||
sql = self.get_template_processor().process_template(self.sql)
|
sql = self.get_template_processor().process_template(
|
||||||
|
self.sql, **self.template_params_dict
|
||||||
|
)
|
||||||
parsed_query = ParsedQuery(sql)
|
parsed_query = ParsedQuery(sql)
|
||||||
if not db_engine_spec.is_readonly_query(parsed_query):
|
if not db_engine_spec.is_readonly_query(parsed_query):
|
||||||
raise SupersetSecurityException(
|
raise SupersetSecurityException(
|
||||||
|
|
|
@ -73,6 +73,25 @@ class TestDatasource(SupersetTestCase):
|
||||||
session.delete(table)
|
session.delete(table)
|
||||||
session.commit()
|
session.commit()
|
||||||
|
|
||||||
|
def test_external_metadata_for_virtual_table_template_params(self):
|
||||||
|
self.login(username="admin")
|
||||||
|
session = db.session
|
||||||
|
table = SqlaTable(
|
||||||
|
table_name="dummy_sql_table_with_template_params",
|
||||||
|
database=get_example_database(),
|
||||||
|
sql="select {{ foo }} as intcol",
|
||||||
|
template_params=json.dumps({"foo": "123"}),
|
||||||
|
)
|
||||||
|
session.add(table)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
|
table = self.get_table_by_name("dummy_sql_table_with_template_params")
|
||||||
|
url = f"/datasource/external_metadata/table/{table.id}/"
|
||||||
|
resp = self.get_json_resp(url)
|
||||||
|
assert {o.get("name") for o in resp} == {"intcol"}
|
||||||
|
session.delete(table)
|
||||||
|
session.commit()
|
||||||
|
|
||||||
def test_external_metadata_for_malicious_virtual_table(self):
|
def test_external_metadata_for_malicious_virtual_table(self):
|
||||||
self.login(username="admin")
|
self.login(username="admin")
|
||||||
table = SqlaTable(
|
table = SqlaTable(
|
||||||
|
|
Loading…
Reference in New Issue