mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
chore: rename ImportMixin to ImportExportMixin (#11460)
* Add UUID to saved_query * Reuse function from previous migration * Point to new head * feat: add backend to export saved queries using new format * Rename ImportMixin to ImportExportMixin
This commit is contained in:
parent
21f722c9bc
commit
f2b8d6aef8
@ -25,7 +25,7 @@ from sqlalchemy.orm import foreign, Query, relationship, RelationshipProperty
|
||||
|
||||
from superset import security_manager
|
||||
from superset.constants import NULL_STRING
|
||||
from superset.models.helpers import AuditMixinNullable, ImportMixin, QueryResult
|
||||
from superset.models.helpers import AuditMixinNullable, ImportExportMixin, QueryResult
|
||||
from superset.models.slice import Slice
|
||||
from superset.typing import FilterValue, FilterValues, QueryObjectDict
|
||||
from superset.utils import core as utils
|
||||
@ -59,7 +59,7 @@ class DatasourceKind(str, Enum):
|
||||
|
||||
|
||||
class BaseDatasource(
|
||||
AuditMixinNullable, ImportMixin
|
||||
AuditMixinNullable, ImportExportMixin
|
||||
): # pylint: disable=too-many-public-methods
|
||||
"""A common interface to objects that are queryable
|
||||
(tables and datasources)"""
|
||||
@ -482,7 +482,7 @@ class BaseDatasource(
|
||||
def get_extra_cache_keys( # pylint: disable=no-self-use
|
||||
self, query_obj: QueryObjectDict # pylint: disable=unused-argument
|
||||
) -> List[Hashable]:
|
||||
""" If a datasource needs to provide additional keys for calculation of
|
||||
"""If a datasource needs to provide additional keys for calculation of
|
||||
cache keys, those can be provided via this method
|
||||
|
||||
:param query_obj: The dict representation of a query object
|
||||
@ -508,7 +508,7 @@ class BaseDatasource(
|
||||
security_manager.raise_for_access(datasource=self)
|
||||
|
||||
|
||||
class BaseColumn(AuditMixinNullable, ImportMixin):
|
||||
class BaseColumn(AuditMixinNullable, ImportExportMixin):
|
||||
"""Interface for column"""
|
||||
|
||||
__tablename__: Optional[str] = None # {connector_name}_column
|
||||
@ -580,7 +580,7 @@ class BaseColumn(AuditMixinNullable, ImportMixin):
|
||||
return {s: getattr(self, s) for s in attrs if hasattr(self, s)}
|
||||
|
||||
|
||||
class BaseMetric(AuditMixinNullable, ImportMixin):
|
||||
class BaseMetric(AuditMixinNullable, ImportExportMixin):
|
||||
|
||||
"""Interface for Metrics"""
|
||||
|
||||
|
@ -54,7 +54,7 @@ from superset.connectors.base.models import BaseColumn, BaseDatasource, BaseMetr
|
||||
from superset.constants import NULL_STRING
|
||||
from superset.exceptions import SupersetException
|
||||
from superset.models.core import Database
|
||||
from superset.models.helpers import AuditMixinNullable, ImportMixin, QueryResult
|
||||
from superset.models.helpers import AuditMixinNullable, ImportExportMixin, QueryResult
|
||||
from superset.typing import FilterValues, Granularity, Metric, QueryObjectDict
|
||||
from superset.utils import core as utils, import_datasource
|
||||
|
||||
@ -121,7 +121,7 @@ def _fetch_metadata_for(datasource: "DruidDatasource") -> Optional[Dict[str, Any
|
||||
return datasource.latest_metadata()
|
||||
|
||||
|
||||
class DruidCluster(Model, AuditMixinNullable, ImportMixin):
|
||||
class DruidCluster(Model, AuditMixinNullable, ImportExportMixin):
|
||||
|
||||
"""ORM object referencing the Druid clusters"""
|
||||
|
||||
@ -616,9 +616,9 @@ class DruidDatasource(Model, BaseDatasource):
|
||||
) -> int:
|
||||
"""Imports the datasource from the object to the database.
|
||||
|
||||
Metrics and columns and datasource will be overridden if exists.
|
||||
This function can be used to import/export dashboards between multiple
|
||||
superset instances. Audit metadata isn't copies over.
|
||||
Metrics and columns and datasource will be overridden if exists.
|
||||
This function can be used to import/export dashboards between multiple
|
||||
superset instances. Audit metadata isn't copies over.
|
||||
"""
|
||||
|
||||
def lookup_datasource(d: DruidDatasource) -> Optional[DruidDatasource]:
|
||||
@ -1082,12 +1082,12 @@ class DruidDatasource(Model, BaseDatasource):
|
||||
adhoc_metrics: Optional[List[Dict[str, Any]]] = None,
|
||||
) -> "OrderedDict[str, Any]":
|
||||
"""
|
||||
Returns a dictionary of aggregation metric names to aggregation json objects
|
||||
Returns a dictionary of aggregation metric names to aggregation json objects
|
||||
|
||||
:param metrics_dict: dictionary of all the metrics
|
||||
:param saved_metrics: list of saved metric names
|
||||
:param adhoc_metrics: list of adhoc metric names
|
||||
:raise SupersetException: if one or more metric names are not aggregations
|
||||
:param metrics_dict: dictionary of all the metrics
|
||||
:param saved_metrics: list of saved metric names
|
||||
:param adhoc_metrics: list of adhoc metric names
|
||||
:raise SupersetException: if one or more metric names are not aggregations
|
||||
"""
|
||||
if not adhoc_metrics:
|
||||
adhoc_metrics = []
|
||||
@ -1193,8 +1193,7 @@ class DruidDatasource(Model, BaseDatasource):
|
||||
client: Optional["PyDruid"] = None,
|
||||
order_desc: bool = True,
|
||||
) -> str:
|
||||
"""Runs a query against Druid and returns a dataframe.
|
||||
"""
|
||||
"""Runs a query against Druid and returns a dataframe."""
|
||||
# TODO refactor into using a TBD Query object
|
||||
client = client or self.cluster.get_pydruid_client()
|
||||
row_limit = row_limit or conf.get("ROW_LIMIT")
|
||||
|
@ -54,7 +54,7 @@ from sqlalchemy_utils import EncryptedType
|
||||
|
||||
from superset import app, db_engine_specs, is_feature_enabled, security_manager
|
||||
from superset.db_engine_specs.base import TimeGrain
|
||||
from superset.models.helpers import AuditMixinNullable, ImportMixin
|
||||
from superset.models.helpers import AuditMixinNullable, ImportExportMixin
|
||||
from superset.models.tags import FavStarUpdater
|
||||
from superset.result_set import SupersetResultSet
|
||||
from superset.utils import cache as cache_util, core as utils
|
||||
@ -98,7 +98,7 @@ class CssTemplate(Model, AuditMixinNullable):
|
||||
|
||||
|
||||
class Database(
|
||||
Model, AuditMixinNullable, ImportMixin
|
||||
Model, AuditMixinNullable, ImportExportMixin
|
||||
): # pylint: disable=too-many-public-methods
|
||||
|
||||
"""An ORM object that stores Database related information"""
|
||||
|
@ -55,7 +55,7 @@ from superset import (
|
||||
from superset.connectors.base.models import BaseDatasource
|
||||
from superset.connectors.druid.models import DruidColumn, DruidMetric
|
||||
from superset.connectors.sqla.models import SqlMetric, TableColumn
|
||||
from superset.models.helpers import AuditMixinNullable, ImportMixin
|
||||
from superset.models.helpers import AuditMixinNullable, ImportExportMixin
|
||||
from superset.models.slice import Slice
|
||||
from superset.models.tags import DashboardUpdater
|
||||
from superset.models.user_attributes import UserAttribute
|
||||
@ -129,7 +129,7 @@ dashboard_user = Table(
|
||||
|
||||
|
||||
class Dashboard( # pylint: disable=too-many-instance-attributes
|
||||
Model, AuditMixinNullable, ImportMixin
|
||||
Model, AuditMixinNullable, ImportExportMixin
|
||||
):
|
||||
|
||||
"""The dashboard object!"""
|
||||
|
@ -68,8 +68,7 @@ def convert_uuids(obj: Any) -> Any:
|
||||
return obj
|
||||
|
||||
|
||||
# TODO (betodealmeida): rename to ImportExportMixin
|
||||
class ImportMixin:
|
||||
class ImportExportMixin:
|
||||
uuid = sa.Column(
|
||||
UUIDType(binary=True), primary_key=False, unique=True, default=uuid.uuid4
|
||||
)
|
||||
|
@ -25,7 +25,7 @@ from sqlalchemy.orm import relationship, RelationshipProperty
|
||||
|
||||
from superset import security_manager
|
||||
from superset.models.alerts import Alert
|
||||
from superset.models.helpers import AuditMixinNullable, ImportMixin
|
||||
from superset.models.helpers import AuditMixinNullable, ImportExportMixin
|
||||
|
||||
metadata = Model.metadata # pylint: disable=no-member
|
||||
|
||||
@ -74,7 +74,9 @@ class EmailSchedule:
|
||||
delivery_type = Column(Enum(EmailDeliveryType))
|
||||
|
||||
|
||||
class DashboardEmailSchedule(Model, AuditMixinNullable, ImportMixin, EmailSchedule):
|
||||
class DashboardEmailSchedule(
|
||||
Model, AuditMixinNullable, ImportExportMixin, EmailSchedule
|
||||
):
|
||||
__tablename__ = "dashboard_email_schedules"
|
||||
dashboard_id = Column(Integer, ForeignKey("dashboards.id"))
|
||||
dashboard = relationship(
|
||||
@ -82,7 +84,7 @@ class DashboardEmailSchedule(Model, AuditMixinNullable, ImportMixin, EmailSchedu
|
||||
)
|
||||
|
||||
|
||||
class SliceEmailSchedule(Model, AuditMixinNullable, ImportMixin, EmailSchedule):
|
||||
class SliceEmailSchedule(Model, AuditMixinNullable, ImportExportMixin, EmailSchedule):
|
||||
__tablename__ = "slice_email_schedules"
|
||||
slice_id = Column(Integer, ForeignKey("slices.id"))
|
||||
slice = relationship("Slice", backref="email_schedules", foreign_keys=[slice_id])
|
||||
|
@ -30,7 +30,7 @@ from sqlalchemy.orm.mapper import Mapper
|
||||
|
||||
from superset import ConnectorRegistry, db, is_feature_enabled, security_manager
|
||||
from superset.legacy import update_time_range
|
||||
from superset.models.helpers import AuditMixinNullable, ImportMixin
|
||||
from superset.models.helpers import AuditMixinNullable, ImportExportMixin
|
||||
from superset.models.tags import ChartUpdater
|
||||
from superset.tasks.thumbnails import cache_chart_thumbnail
|
||||
from superset.utils import core as utils
|
||||
@ -56,7 +56,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Slice(
|
||||
Model, AuditMixinNullable, ImportMixin
|
||||
Model, AuditMixinNullable, ImportExportMixin
|
||||
): # pylint: disable=too-many-public-methods
|
||||
|
||||
"""A slice is essentially a report or a view on data"""
|
||||
|
@ -39,7 +39,11 @@ from sqlalchemy.engine.url import URL
|
||||
from sqlalchemy.orm import backref, relationship
|
||||
|
||||
from superset import security_manager
|
||||
from superset.models.helpers import AuditMixinNullable, ExtraJSONMixin, ImportMixin
|
||||
from superset.models.helpers import (
|
||||
AuditMixinNullable,
|
||||
ExtraJSONMixin,
|
||||
ImportExportMixin,
|
||||
)
|
||||
from superset.models.tags import QueryUpdater
|
||||
from superset.sql_parse import CtasMethod, ParsedQuery, Table
|
||||
from superset.utils.core import QueryStatus, user_label
|
||||
@ -162,7 +166,7 @@ class Query(Model, ExtraJSONMixin):
|
||||
security_manager.raise_for_access(query=self)
|
||||
|
||||
|
||||
class SavedQuery(Model, AuditMixinNullable, ExtraJSONMixin, ImportMixin):
|
||||
class SavedQuery(Model, AuditMixinNullable, ExtraJSONMixin, ImportExportMixin):
|
||||
"""ORM model for SQL query"""
|
||||
|
||||
__tablename__ = "saved_query"
|
||||
|
@ -53,7 +53,7 @@ from superset.exceptions import (
|
||||
SupersetSecurityException,
|
||||
SupersetTimeoutException,
|
||||
)
|
||||
from superset.models.helpers import ImportMixin
|
||||
from superset.models.helpers import ImportExportMixin
|
||||
from superset.translations.utils import get_language_pack
|
||||
from superset.typing import FlaskResponse
|
||||
from superset.utils import core as utils
|
||||
@ -378,7 +378,7 @@ class YamlExportMixin: # pylint: disable=too-few-public-methods
|
||||
|
||||
@action("yaml_export", __("Export to YAML"), __("Export to YAML?"), "fa-download")
|
||||
def yaml_export(
|
||||
self, items: Union[ImportMixin, List[ImportMixin]]
|
||||
self, items: Union[ImportExportMixin, List[ImportExportMixin]]
|
||||
) -> FlaskResponse:
|
||||
if not isinstance(items, list):
|
||||
items = [items]
|
||||
@ -395,11 +395,11 @@ class YamlExportMixin: # pylint: disable=too-few-public-methods
|
||||
class DeleteMixin: # pylint: disable=too-few-public-methods
|
||||
def _delete(self: BaseView, primary_key: int) -> None:
|
||||
"""
|
||||
Delete function logic, override to implement diferent logic
|
||||
deletes the record with primary_key = primary_key
|
||||
Delete function logic, override to implement diferent logic
|
||||
deletes the record with primary_key = primary_key
|
||||
|
||||
:param primary_key:
|
||||
record primary key to delete
|
||||
:param primary_key:
|
||||
record primary key to delete
|
||||
"""
|
||||
item = self.datamodel.get(primary_key, self._base_filters)
|
||||
if not item:
|
||||
|
Loading…
Reference in New Issue
Block a user