From aafb54d042513d4f3c4ed8df85e2c5d1cd05c11e Mon Sep 17 00:00:00 2001 From: John Bodley <4567245+john-bodley@users.noreply.github.com> Date: Sat, 16 Dec 2023 14:11:58 +1300 Subject: [PATCH] chore: Ensure Mixins are ordered according to the MRO (#26288) --- superset/connectors/sqla/models.py | 4 ++-- superset/databases/schemas.py | 6 +++--- superset/databases/ssh_tunnel/models.py | 2 +- superset/datasets/models.py | 2 +- superset/db_engine_specs/clickhouse.py | 2 +- superset/db_engine_specs/databend.py | 2 +- superset/db_engine_specs/databricks.py | 2 +- superset/db_engine_specs/mysql.py | 2 +- superset/db_engine_specs/postgres.py | 2 +- superset/db_engine_specs/redshift.py | 2 +- superset/key_value/models.py | 2 +- .../2016-06-27_08-43_27ae655e4247_make_creator_owners.py | 4 ++-- .../2018-07-26_11-10_c82ee8a39623_add_implicit_tags.py | 2 +- ..._17-57_b56500de1855_add_uuid_column_to_import_mixin.py | 2 +- ...21-09_96e99fb176a0_add_import_mixing_to_saved_query.py | 2 +- ...-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py | 2 +- superset/models/dashboard.py | 2 +- superset/models/sql_lab.py | 8 ++++---- superset/reports/models.py | 2 +- superset/tables/models.py | 2 +- tests/integration_tests/charts/api_tests.py | 2 +- tests/integration_tests/dashboards/api_tests.py | 2 +- tests/integration_tests/profile_tests.py | 2 +- tests/unit_tests/databases/schema_tests.py | 2 +- 24 files changed, 31 insertions(+), 31 deletions(-) diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py index 598bc6741b07c..55abaaf68bf07 100644 --- a/superset/connectors/sqla/models.py +++ b/superset/connectors/sqla/models.py @@ -757,7 +757,7 @@ def values_for_column(self, column_name: str, limit: int = 10000) -> list[Any]: raise NotImplementedError() -class TableColumn(Model, AuditMixinNullable, ImportExportMixin, CertificationMixin): +class TableColumn(AuditMixinNullable, ImportExportMixin, CertificationMixin, Model): """ORM object for table columns, each table can have multiple columns""" @@ -971,7 +971,7 @@ def data(self) -> dict[str, Any]: return {s: getattr(self, s) for s in attrs if hasattr(self, s)} -class SqlMetric(Model, AuditMixinNullable, ImportExportMixin, CertificationMixin): +class SqlMetric(AuditMixinNullable, ImportExportMixin, CertificationMixin, Model): """ORM object for metrics, each table can have multiple metrics""" diff --git a/superset/databases/schemas.py b/superset/databases/schemas.py index b56c98c5d64b5..65005824d5715 100644 --- a/superset/databases/schemas.py +++ b/superset/databases/schemas.py @@ -422,7 +422,7 @@ class DatabaseSSHTunnel(Schema): private_key_password = fields.String(required=False) -class DatabasePostSchema(Schema, DatabaseParametersSchemaMixin): +class DatabasePostSchema(DatabaseParametersSchemaMixin, Schema): class Meta: # pylint: disable=too-few-public-methods unknown = EXCLUDE @@ -479,7 +479,7 @@ class Meta: # pylint: disable=too-few-public-methods ssh_tunnel = fields.Nested(DatabaseSSHTunnel, allow_none=True) -class DatabasePutSchema(Schema, DatabaseParametersSchemaMixin): +class DatabasePutSchema(DatabaseParametersSchemaMixin, Schema): class Meta: # pylint: disable=too-few-public-methods unknown = EXCLUDE @@ -536,7 +536,7 @@ class Meta: # pylint: disable=too-few-public-methods uuid = fields.String(required=False) -class DatabaseTestConnectionSchema(Schema, DatabaseParametersSchemaMixin): +class DatabaseTestConnectionSchema(DatabaseParametersSchemaMixin, Schema): rename_encrypted_extra = pre_load(rename_encrypted_extra) database_name = fields.String( diff --git a/superset/databases/ssh_tunnel/models.py b/superset/databases/ssh_tunnel/models.py index d9462a63db87f..3d1411cc80c01 100644 --- a/superset/databases/ssh_tunnel/models.py +++ b/superset/databases/ssh_tunnel/models.py @@ -34,7 +34,7 @@ app_config = current_app.config -class SSHTunnel(Model, AuditMixinNullable, ExtraJSONMixin, ImportExportMixin): +class SSHTunnel(AuditMixinNullable, ExtraJSONMixin, ImportExportMixin, Model): """ A ssh tunnel configuration in a database. """ diff --git a/superset/datasets/models.py b/superset/datasets/models.py index 50aeea7b51672..aa5d0fe72c5b9 100644 --- a/superset/datasets/models.py +++ b/superset/datasets/models.py @@ -69,7 +69,7 @@ ) -class Dataset(Model, AuditMixinNullable, ExtraJSONMixin, ImportExportMixin): +class Dataset(AuditMixinNullable, ExtraJSONMixin, ImportExportMixin, Model): """ A table/view in a database. """ diff --git a/superset/db_engine_specs/clickhouse.py b/superset/db_engine_specs/clickhouse.py index 4c5ec44d56f57..4346f77d64590 100644 --- a/superset/db_engine_specs/clickhouse.py +++ b/superset/db_engine_specs/clickhouse.py @@ -248,7 +248,7 @@ class ClickHouseParametersSchema(Schema): pass -class ClickHouseConnectEngineSpec(ClickHouseEngineSpec, BasicParametersMixin): +class ClickHouseConnectEngineSpec(BasicParametersMixin, ClickHouseEngineSpec): """Engine spec for clickhouse-connect connector""" engine = "clickhousedb" diff --git a/superset/db_engine_specs/databend.py b/superset/db_engine_specs/databend.py index 589e8b9168e26..8ad4713024fb3 100644 --- a/superset/db_engine_specs/databend.py +++ b/superset/db_engine_specs/databend.py @@ -194,7 +194,7 @@ class DatabendParametersSchema(Schema): ) -class DatabendConnectEngineSpec(DatabendEngineSpec, BasicParametersMixin): +class DatabendConnectEngineSpec(BasicParametersMixin, DatabendEngineSpec): """Engine spec for databend sqlalchemy connector""" engine = "databend" diff --git a/superset/db_engine_specs/databricks.py b/superset/db_engine_specs/databricks.py index 1cbf4a238d101..4b2f93ca5d736 100644 --- a/superset/db_engine_specs/databricks.py +++ b/superset/db_engine_specs/databricks.py @@ -145,7 +145,7 @@ def epoch_to_dttm(cls) -> str: return HiveEngineSpec.epoch_to_dttm() -class DatabricksNativeEngineSpec(DatabricksODBCEngineSpec, BasicParametersMixin): +class DatabricksNativeEngineSpec(BasicParametersMixin, DatabricksODBCEngineSpec): engine_name = "Databricks" engine = "databricks" diff --git a/superset/db_engine_specs/mysql.py b/superset/db_engine_specs/mysql.py index 687ffee7d565b..fc0606697be2c 100644 --- a/superset/db_engine_specs/mysql.py +++ b/superset/db_engine_specs/mysql.py @@ -62,7 +62,7 @@ ) -class MySQLEngineSpec(BaseEngineSpec, BasicParametersMixin): +class MySQLEngineSpec(BasicParametersMixin, BaseEngineSpec): engine = "mysql" engine_name = "MySQL" max_column_name_length = 64 diff --git a/superset/db_engine_specs/postgres.py b/superset/db_engine_specs/postgres.py index 7512aac6067d3..7f542365dc452 100644 --- a/superset/db_engine_specs/postgres.py +++ b/superset/db_engine_specs/postgres.py @@ -183,7 +183,7 @@ def epoch_to_dttm(cls) -> str: return "(timestamp 'epoch' + {col} * interval '1 second')" -class PostgresEngineSpec(PostgresBaseEngineSpec, BasicParametersMixin): +class PostgresEngineSpec(BasicParametersMixin, PostgresBaseEngineSpec): engine = "postgresql" engine_aliases = {"postgres"} supports_dynamic_schema = True diff --git a/superset/db_engine_specs/redshift.py b/superset/db_engine_specs/redshift.py index 2e746a6349365..925e0424e41e2 100644 --- a/superset/db_engine_specs/redshift.py +++ b/superset/db_engine_specs/redshift.py @@ -55,7 +55,7 @@ ) -class RedshiftEngineSpec(PostgresBaseEngineSpec, BasicParametersMixin): +class RedshiftEngineSpec(BasicParametersMixin, PostgresBaseEngineSpec): engine = "redshift" engine_name = "Amazon Redshift" max_column_name_length = 127 diff --git a/superset/key_value/models.py b/superset/key_value/models.py index f92457d190178..7a3f5e52a2f30 100644 --- a/superset/key_value/models.py +++ b/superset/key_value/models.py @@ -24,7 +24,7 @@ VALUE_MAX_SIZE = 2**24 - 1 -class KeyValueEntry(Model, AuditMixinNullable, ImportExportMixin): +class KeyValueEntry(AuditMixinNullable, ImportExportMixin, Model): """Key value store entity""" __tablename__ = "key_value" diff --git a/superset/migrations/versions/2016-06-27_08-43_27ae655e4247_make_creator_owners.py b/superset/migrations/versions/2016-06-27_08-43_27ae655e4247_make_creator_owners.py index 60c5a6687ea58..1bf5e2ecafa18 100644 --- a/superset/migrations/versions/2016-06-27_08-43_27ae655e4247_make_creator_owners.py +++ b/superset/migrations/versions/2016-06-27_08-43_27ae655e4247_make_creator_owners.py @@ -79,7 +79,7 @@ def created_by(cls): ) -class Slice(Base, AuditMixin): +class Slice(AuditMixin, Base): """Declarative class to do query in upgrade""" __tablename__ = "slices" @@ -87,7 +87,7 @@ class Slice(Base, AuditMixin): owners = relationship("User", secondary=slice_user) -class Dashboard(Base, AuditMixin): +class Dashboard(AuditMixin, Base): """Declarative class to do query in upgrade""" __tablename__ = "dashboards" diff --git a/superset/migrations/versions/2018-07-26_11-10_c82ee8a39623_add_implicit_tags.py b/superset/migrations/versions/2018-07-26_11-10_c82ee8a39623_add_implicit_tags.py index c6a66d6b531aa..75151d3403c9b 100644 --- a/superset/migrations/versions/2018-07-26_11-10_c82ee8a39623_add_implicit_tags.py +++ b/superset/migrations/versions/2018-07-26_11-10_c82ee8a39623_add_implicit_tags.py @@ -80,7 +80,7 @@ class Tag(Base, AuditMixinNullable): type = Column(Enum(TagType)) -class TaggedObject(Base, AuditMixinNullable): +class TaggedObject(AuditMixinNullable, Base): __tablename__ = "tagged_object" id = Column(Integer, primary_key=True) diff --git a/superset/migrations/versions/2020-09-28_17-57_b56500de1855_add_uuid_column_to_import_mixin.py b/superset/migrations/versions/2020-09-28_17-57_b56500de1855_add_uuid_column_to_import_mixin.py index 574ca1536a34c..980ca56f62e90 100644 --- a/superset/migrations/versions/2020-09-28_17-57_b56500de1855_add_uuid_column_to_import_mixin.py +++ b/superset/migrations/versions/2020-09-28_17-57_b56500de1855_add_uuid_column_to_import_mixin.py @@ -68,7 +68,7 @@ class ImportMixin: "slice_email_schedules", ] models = { - table_name: type(table_name, (Base, ImportMixin), {"__tablename__": table_name}) + table_name: type(table_name, (ImportMixin, Base), {"__tablename__": table_name}) for table_name in table_names } diff --git a/superset/migrations/versions/2020-10-21_21-09_96e99fb176a0_add_import_mixing_to_saved_query.py b/superset/migrations/versions/2020-10-21_21-09_96e99fb176a0_add_import_mixing_to_saved_query.py index ffe0caf64c90d..bda21e47524ac 100644 --- a/superset/migrations/versions/2020-10-21_21-09_96e99fb176a0_add_import_mixing_to_saved_query.py +++ b/superset/migrations/versions/2020-10-21_21-09_96e99fb176a0_add_import_mixing_to_saved_query.py @@ -47,7 +47,7 @@ class ImportMixin: uuid = sa.Column(UUIDType(binary=True), primary_key=False, default=uuid4) -class SavedQuery(Base, ImportMixin): +class SavedQuery(ImportMixin, Base): __tablename__ = "saved_query" diff --git a/superset/migrations/versions/2022-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py b/superset/migrations/versions/2022-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py index b51f6c78ac470..a1e0f855fc8bd 100644 --- a/superset/migrations/versions/2022-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py +++ b/superset/migrations/versions/2022-04-01_14-38_a9422eeaae74_new_dataset_models_take_2.py @@ -257,7 +257,7 @@ class NewTable(AuxiliaryColumnsMixin, Base): ) -class NewDataset(Base, AuxiliaryColumnsMixin): +class NewDataset(AuxiliaryColumnsMixin, Base): __tablename__ = "sl_datasets" id = sa.Column(sa.Integer, primary_key=True) diff --git a/superset/models/dashboard.py b/superset/models/dashboard.py index 919c832ab5b4f..b965c8f6a0a07 100644 --- a/superset/models/dashboard.py +++ b/superset/models/dashboard.py @@ -147,7 +147,7 @@ def copy_dashboard(_mapper: Mapper, connection: Connection, target: Dashboard) - # pylint: disable=too-many-public-methods -class Dashboard(Model, AuditMixinNullable, ImportExportMixin): +class Dashboard(AuditMixinNullable, ImportExportMixin, Model): """The dashboard object!""" __tablename__ = "dashboards" diff --git a/superset/models/sql_lab.py b/superset/models/sql_lab.py index 7e63e984df0bc..ca530ff8b97f5 100644 --- a/superset/models/sql_lab.py +++ b/superset/models/sql_lab.py @@ -66,7 +66,7 @@ class Query( - Model, ExtraJSONMixin, ExploreMixin + ExtraJSONMixin, ExploreMixin, Model ): # pylint: disable=abstract-method,too-many-public-methods """ORM model for SQL query @@ -355,7 +355,7 @@ def adhoc_column_to_sqla( return self.make_sqla_column_compatible(sqla_column, label) -class SavedQuery(Model, AuditMixinNullable, ExtraJSONMixin, ImportExportMixin): +class SavedQuery(AuditMixinNullable, ExtraJSONMixin, ImportExportMixin, Model): """ORM model for SQL query""" __tablename__ = "saved_query" @@ -442,7 +442,7 @@ def last_run_delta_humanized(self) -> str: return self._last_run_delta_humanized -class TabState(Model, AuditMixinNullable, ExtraJSONMixin): +class TabState(AuditMixinNullable, ExtraJSONMixin, Model): __tablename__ = "tab_state" # basic info @@ -505,7 +505,7 @@ def to_dict(self) -> dict[str, Any]: } -class TableSchema(Model, AuditMixinNullable, ExtraJSONMixin): +class TableSchema(AuditMixinNullable, ExtraJSONMixin, Model): __tablename__ = "table_schema" id = Column(Integer, primary_key=True, autoincrement=True) diff --git a/superset/reports/models.py b/superset/reports/models.py index 5c47f414563af..1eb38af8b5fec 100644 --- a/superset/reports/models.py +++ b/superset/reports/models.py @@ -106,7 +106,7 @@ class ReportSourceFormat(StrEnum): ) -class ReportSchedule(Model, AuditMixinNullable, ExtraJSONMixin): +class ReportSchedule(AuditMixinNullable, ExtraJSONMixin, Model): """ Report Schedules, supports alerts and reports diff --git a/superset/tables/models.py b/superset/tables/models.py index dccb4f7f04d92..11f1021197d26 100644 --- a/superset/tables/models.py +++ b/superset/tables/models.py @@ -64,7 +64,7 @@ ) -class Table(Model, AuditMixinNullable, ExtraJSONMixin, ImportExportMixin): +class Table(AuditMixinNullable, ExtraJSONMixin, ImportExportMixin, Model): """ A table/view in a database. """ diff --git a/tests/integration_tests/charts/api_tests.py b/tests/integration_tests/charts/api_tests.py index 69888104fa4ef..a58ce1779e51a 100644 --- a/tests/integration_tests/charts/api_tests.py +++ b/tests/integration_tests/charts/api_tests.py @@ -73,7 +73,7 @@ CHARTS_FIXTURE_COUNT = 10 -class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixin): +class TestChartApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCase): resource_name = "chart" @pytest.fixture(autouse=True) diff --git a/tests/integration_tests/dashboards/api_tests.py b/tests/integration_tests/dashboards/api_tests.py index a5c44f9f08764..6b435da997fa8 100644 --- a/tests/integration_tests/dashboards/api_tests.py +++ b/tests/integration_tests/dashboards/api_tests.py @@ -63,7 +63,7 @@ DASHBOARDS_FIXTURE_COUNT = 10 -class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixin): +class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCase): resource_name = "dashboard" dashboards: list[Dashboard] = [] diff --git a/tests/integration_tests/profile_tests.py b/tests/integration_tests/profile_tests.py index aa5448139e707..5a0efc7509a5b 100644 --- a/tests/integration_tests/profile_tests.py +++ b/tests/integration_tests/profile_tests.py @@ -31,7 +31,7 @@ from .base_tests import SupersetTestCase -class TestProfile(SupersetTestCase, InsertChartMixin): +class TestProfile(InsertChartMixin, SupersetTestCase): def insert_dashboard_created_by(self, username: str) -> Dashboard: user = self.get_user(username) dashboard = self.insert_dashboard( diff --git a/tests/unit_tests/databases/schema_tests.py b/tests/unit_tests/databases/schema_tests.py index c9fca22d1b28d..b86f1b4afebeb 100644 --- a/tests/unit_tests/databases/schema_tests.py +++ b/tests/unit_tests/databases/schema_tests.py @@ -42,7 +42,7 @@ def dummy_schema() -> "DatabaseParametersSchemaMixin": """ from superset.databases.schemas import DatabaseParametersSchemaMixin - class DummySchema(Schema, DatabaseParametersSchemaMixin): + class DummySchema(DatabaseParametersSchemaMixin, Schema): sqlalchemy_uri = fields.String() return DummySchema()