fix: move columns to datasource object for bootstrap data (#20203)

* move columns to datasource

* address concerns
This commit is contained in:
Hugh A. Miles II 2022-05-31 23:37:49 +02:00 committed by GitHub
parent e07ee6c764
commit 9432c62ec1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View File

@ -166,6 +166,10 @@ class Query(Model, ExtraJSONMixin):
def sql_tables(self) -> List[Table]:
return list(ParsedQuery(self.sql).tables)
@property
def columns(self) -> List[Table]:
return self.extra.get("columns", [])
def raise_for_access(self) -> None:
"""
Raise an exception if the user cannot access the resource.

View File

@ -889,11 +889,10 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
except (SupersetException, SQLAlchemyError):
datasource_data = dummy_datasource_data
columns: List[Dict[str, Any]] = []
if datasource:
datasource_data["owners"] = datasource.owners_data
if isinstance(datasource, Query):
columns = datasource.extra.get("columns", [])
datasource_data["columns"] = datasource.columns
bootstrap_data = {
"can_add": slice_add_perm,
@ -908,7 +907,6 @@ class Superset(BaseSupersetView): # pylint: disable=too-many-public-methods
"user": bootstrap_user_data(g.user, include_perms=True),
"forced_height": request.args.get("height"),
"common": common_bootstrap_payload(),
"columns": columns,
}
if slc:
title = slc.slice_name